﻿function killErrors() {
    return true;
}

window.onerror = killErrors;
window.top.c1 = 0;

function isSupportedIE() {
    var userAgent = navigator.userAgent.toLowerCase();

    // IE Check supports ActiveX controls
    if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("mac") == -1 && userAgent.indexOf("opera") == -1) {
        var version = navigator.appVersion.match(/MSIE (.\..)/)[1];
        if (version >= 5.5) {
            return true;
        } else {
            return false;
        }
    }
}
//thunder del var isIE = isSupportedIE();

function to_html(str) {
    str = str.replace(/\</ig, "&lt;");
    str = str.replace(/\>/ig, "&gt;");
    str = str.replace(/\&/ig, "&amp;");
    //str=str.replace(/\"/ig,"&quot;");
    return str;
}

function to_html3(str) {
    str = str.replace(/\'/g, "’"); //'''替换半角单引号为全角单引号
    str = str.replace(/\"/g, "”"); //"""替换半角双引号为全角双引号
    str = str.replace(/</g, "《").replace(/>/g, "》"); //"""
    return str;
}


function to_html2(str) {
    str = str.replace(/\'/g, "’"); //'''
    return str;
}


//去除字符串的头尾空格
function trim(strSource) {
    var i;
    var sTemp;
    var iIndex;
    i = strSource.length;
    if (i == 0) return "";
    sTemp = strSource;
    for (iIndex = 0; iIndex < i; iIndex++) {
        if (strSource.substring(iIndex, iIndex + 1) == " ") {
        } else {
            sTemp = strSource.substring(iIndex, i);
            break;
        }
    }
    if (iIndex == i) return "";
    for (iIndex = sTemp.length; iIndex > 0; iIndex--) {
        if (sTemp.substring(iIndex - 1, iIndex) == " ") {
        } else {
            sTemp = sTemp.substring(0, iIndex);
            break;
        }
    }

    return sTemp;
}

/******************************************/
/*功能：弹出窗体                          */
/*参数：URL 地址,TYPE 模式/全屏,SC 是否显示滚动条*/
/*      iW 宽度,iH 高度,TOP 头部位置,LEFT 左边位置,*/
/*      R 改变大小,S 状态栏显示,T,TB 帮助显示*/
/*返回：无                                */
/******************************************/
function OWOLD(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var tempObj = document.getElementById("tagOpenWin");
    if (tempObj == null) {
        tempObj = document.createElement('a');
        tempObj.id = 'tagOpenWin';
        tempObj.target = '_blank';
        document.body.appendChild(tempObj);
    }

    tempObj.setAttribute('href', URL);
    tempObj.click();

    /*
    var sF="dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;
	
    sF+="scrollbars="+(SC?SC:"NO")+",";
	
    if (TYPE=="full"){
    sF+=" Width=1015,";
    sF+=" Height=698,";
    sF+=" Top=0,";
    sF+=" Left=0,";
    window.open(URL, "_blank", sF, false);
    return;
    }
	
    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF+=" Width=860,";
    sF+=" Height=570,";
    sF+=" Top=50,";
    sF+=" Left=50,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    //alert('sF='+sF+',type='+TYPE);
	
    if (TYPE=="modal"){
    _rv=window.showModalDialog(URL,"",sF);
    }
    else
    {
    //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
    window.open(URL, "_blank", sF, false);
	
    }
    */
}

function OW(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    //alert('win close:cur frame id='+window.frameElement.id);
    //alert('close:cur frame id='+self.frameElement.id);
    //alert('parent frame id='+parent.frameElement.id);
    //alert('window name='+window.name);
    //window.top.test();
    //alert('ok');
    if (isIE6())
        return OWOLD(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB);
    if (!self.frameElement)
        content_win = 'mainwin';
    else
        content_win = self.frameElement.id;
    //alert(content_win);
    switch (content_win) {
        case 'mainwin':
        case 'homeframe1':
        case 'homeframe2':
            show_popup_div('view', 'viewframe', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'cardframe':
            show_popup_div('view_c', 'viewframe_c', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'chooseframe':
            //alert('parent frame id='+parent.frameElement.id);
            if (parent.frameElement.id == 'viewframe_c')
                show_popup_div('view2_c', 'viewframe2_c', URL);
            else {
                show_popup_div('view2', 'viewframe2', URL);
                window.top.myparentframe['viewframe2'] = 'chooseframe';
            }
            break;
        case 'view_choose_product':
            show_popup_div('view2', 'viewframe2', URL);
            window.top.myparentframe['viewframe2'] = 'view_choose_product';
            break;

        case 'homeframe01':
        case 'homeframe02':
        case 'homeframe03':
        case 'homeframe04':
        case 'homeframe11':
        case 'homeframe12':
        case 'homeframe13':
        case 'homeframe14': //for small list
            show_popup_div('view', 'viewframe', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;

        default:
            break;
    }
    /*
    if (parent.frameElement.id == 'viewframe')
    {
    //window.top.save_opener(window, 'viewframe2');
    show_popup_div('view2', 'viewframe2', URL);
    }
    else
    {
    //alert('ok1');
    //window.top.save_opener(window, 'viewframe');
    //alert('ok2');
    show_popup_div('view', 'viewframe', URL);
    window.top.document.getElementById('fade').style.display='block';
    window.top.document.getElementById('fade').style.height=window.top.document.body.scrollHeight;
    return true;
    }
    */
    //else return false;
}

function OW_FROM_LOCAL_FRAME(URL, view_group_id) {
    MoonCloseWinLocal(view_group_id);

    if (isIE6())
        return OWOLD(URL, 'notfull', 'yes');
    content_win = 'mainwin';

    //alert(content_win);
    switch (content_win) {
        case 'mainwin':
        case 'homeframe1':
        case 'homeframe2':
            show_popup_div('view', 'viewframe', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'cardframe':
            show_popup_div('view_c', 'viewframe_c', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'chooseframe':
            //alert('parent frame id='+parent.frameElement.id);
            if (parent.frameElement.id == 'viewframe_c')
                show_popup_div('view2_c', 'viewframe2_c', URL);
            else
                show_popup_div('view2', 'viewframe2', URL);
            break;
        default:
            break;
    }

}

function OW_LOCAL(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    //alert('win close:cur frame id='+window.frameElement.id);
    //alert('close:cur frame id='+self.frameElement.id);
    //alert('parent frame id='+parent.frameElement.id);
    //alert('window name='+window.name);
    //window.top.test();
    //alert('ok');
    if (isIE6())
        return OWOLD(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB);
    if (!self.frameElement)
        content_win = 'mainwin';
    else
        content_win = self.frameElement.id;
    //alert(content_win);
    switch (content_win) {
        case 'mainwin':
        case 'homeframe1':
        case 'homeframe2':
            show_popup_div_local('view', 'viewframe', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'cardframe':
            show_popup_div('view_c', 'viewframe_c', URL);
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        case 'chooseframe':
            //alert('parent frame id='+parent.frameElement.id);
            if (parent.frameElement.id == 'viewframe_c')
                show_popup_div('view2_c', 'viewframe2_c', URL);
            else
                show_popup_div('view2', 'viewframe2', URL);
            break;
        default:
            break;
    }
}


function OW_LOCAL2(URL, from, frameid) {
    //alert('loaded='+window.top.lf_loaded[frameid]);
    if (typeof (window.top.bodyframe) == "undefined" || window.top.lf_loaded[frameid] != true) //it's normal2
    {
        return OW(URL, 'notfull', 'yes');
    }

    if (isIE6())
        return OWOLD(URL, 'notfull', 'yes');

    view_group_id = hide_all_local_group_frm(frameid);

    if (!view_group_id) return false;

    //to show container
    show_div_full(view_group_id); //only view for local

    //to show frame
    frm = window.top.document.getElementById(frameid); //"view_add_customer");

    frm.style.display = "block";
    frm.contentWindow.load_init(from, URL);

    //to show fade
    switch (from) {
        case 'mainwin':
        case 'shortcuts':
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        default:
            break;
    }

    /*
    if (!self.frameElement)
    content_win='mainwin';
    else
    content_win=self.frameElement.id;
    */
    //alert(content_win);
    /*
    switch(content_win)
    {
    case 'mainwin':
    case 'homeframe1':
    case 'homeframe2':
    show_popup_div_local('view', 'viewframe', URL);
    window.top.document.getElementById('fade').style.display='block';
    window.top.document.getElementById('fade').style.height=window.top.document.body.scrollHeight;
    break;
    case 'cardframe':
    show_popup_div('view_c', 'viewframe_c', URL);
    window.top.document.getElementById('fade').style.display='block';
    window.top.document.getElementById('fade').style.height=window.top.document.body.scrollHeight;
    break;	
    case 'chooseframe':
    //alert('parent frame id='+parent.frameElement.id);
    if (parent.frameElement.id == 'viewframe_c')
    show_popup_div('view2_c', 'viewframe2_c', URL);
    else
    show_popup_div('view2', 'viewframe2', URL);
    break;
    default:
    break;
    }*/
}


function MOON_OW_IE6(URL, view_container, view_body, view_fade, x, y, dis_win, confirm_msg) {
    if (confirm_msg != undefined) {
        if (!confirm(confim_msg))
            return false;
    }

    //if (dis_win == undefined)
    dis_win = window;

    if (view_container == undefined)
        view_container = 'view';
    if (view_body == undefined)
        view_body = 'viewframe';
    if (view_fade == undefined)
        view_fade = 'fade';
    //if (x == undefined)
    x = -1;
    //if (y == undefined)
    y = -1;

    moon_show_popup_div(view_container, view_body, URL, dis_win, x, y);
    if (view_fade != '') {
        dis_win.document.getElementById(view_fade).style.display = 'block';
        dis_win.document.getElementById(view_fade).style.height = dis_win.document.body.scrollHeight;
    }
    return true;

}


function MOON_OW(URL, view_container, view_body, view_fade, x, y, dis_win, confirm_msg) {
    if (isIE6()) return MOON_OW_IE6(URL, view_container, view_body, view_fade, x, y, dis_win, confirm_msg);

    //alert('URL='+URL);
    //alert('view_container='+view_container);
    //alert('view_body='+view_body);
    //alert('view_fade='+view_fade);
    //alert('initx='+x);
    //alert('inity='+y);
    //alert('dis_win='+dis_win);
    //alert('confirm_msg='+confirm_msg);
    if (confirm_msg != undefined) {
        if (!confirm(confim_msg))
            return false;
    }

    if (dis_win == undefined)
        dis_win = window.top;
    if (view_container == undefined)
        view_container = 'view';
    if (view_body == undefined)
        view_body = 'viewframe';
    if (view_fade == undefined)
        view_fade = 'fade';
    if (x == undefined)
        x = 0;
    if (y == undefined)
        y = 0;

    moon_show_popup_div(view_container, view_body, URL, dis_win, x, y);
    if (view_fade != '') {
        dis_win.document.getElementById(view_fade).style.display = 'block';
        dis_win.document.getElementById(view_fade).style.height = dis_win.document.body.scrollHeight;
    }
    return true;

}
function MoonCloseWinOLD() {
    window.opener = null; window.open("", "_self"); window.close();
}

function MoonCloseWin() {
    //ert('win close:cur frame id='+window.frameElement.id);
    //alert('close:cur frame id='+self.frameElement.id);
    //alert('parent frame id='+parent.frameElement.id);

    if (isIE6()) return MoonCloseWinOLD();
    switch (self.frameElement.id) {
        case 'viewframe':
            return MoonCloseWin1();
            break;
        case 'viewframe_c':
            return MoonCloseWinc();
            break;
        case 'viewframe2':
            return MoonCloseWin2();
            break;
        case 'viewframe2_c':
            return MoonCloseWin2c();
            break;
        case 'chooseframe':
            close_div('choose'); close_div('fade');
            break;
        default:
            break;
    }
    /*	
    if (self.frameElement.id == 'viewframe2')
    return MoonCloseWin2();
    else
    return MoonCloseWin1();
    */
}

function MoonCloseWin1() {
    if (isIE6()) return MoonCloseWinOLD();
    window.top.document.getElementById('view').style.display = "none";
    window.top.document.getElementById('fade').style.display = "none";
}

function MoonCloseWinc() {
    if (isIE6()) return MoonCloseWinOLD();
    window.top.document.getElementById('view_c').style.display = "none";
    window.top.document.getElementById('fade').style.display = "none";
}


function MoonCloseWin2() {
    //alert('close:cur frame id='+self.frameElement.id);
    //alert('close:cur frame id='+self.frameElement.id);
    //alert('parent frame id='+parent.frameElement.id);
    if (isIE6()) {
        window.document.getElementById('view2').style.display = "none";
        return;
    }
    window.top.document.getElementById('view2').style.display = "none";
    //window.top.document.getElementById('fade').style.display = "none";
}

function MoonCloseWin2c() {
    if (isIE6()) {
        window.document.getElementById('view2_c').style.display = "none";
        return;
    }
    window.top.document.getElementById('view2_c').style.display = "none";
}


function MoonCloseWinLocal(view_group_id) {
    if (isIE6()) return MoonCloseWinOLD();
    window.top.document.getElementById(view_group_id).style.display = "none";
    window.top.document.getElementById('fade').style.display = "none";
}

function MoonCloseWinChooseLocal(view_group_id) {
    //if (result_action == 'SharedCustomers' || result_action == 'AssignCustomers')
    //	show_parent_obj('cardframe');

    window.top.document.getElementById(view_group_id).style.display = "none";
    window.top.document.getElementById('fade').style.display = "none";
    window.top.cur_opener[view_group_id] = '';
}



/******************************************/
/*客户模块快速搜索用					  */
/*功能：弹出窗体                          */
/*参数：URL 地址,TYPE 模式/全屏,SC 是否显示滚动条*/
/*      iW 宽度,iH 高度,TOP 头部位置,LEFT 左边位置,*/
/*      R 改变大小,S 状态栏显示,T,TB 帮助显示*/
/*返回：无                                */
/******************************************/



function OWXXX(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=50,";
        sF += " Left=50,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=570,";
    sF += " Height=482,";
    sF += " Top=80,";
    sF += " Left=240,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}




function OWQ(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=400,";
    sF += " Height=450,";
    sF += " Top=100,";
    sF += " Left=300,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}

function OWZ(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=211,";
    sF += " Height=280,";
    sF += " Top=100,";
    sF += " Left=300,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}

function OWN(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    sF += " Width=1015,";
    sF += " Height=698,";
    sF += " Top=0,";
    sF += " Left=0,";
    window.open(URL);
    return;
}



function OWX(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=211,";
    sF += " Height=280,";
    sF += " Top=100,";
    sF += " LEFT=600,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", "top=200, left=300, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);

    }
}

/******************************************/
/*功能：弹出窗体                          */
/*参数：URL 地址,TYPE 模式/全屏,SC 是否显示滚动条*/
/*      iW 宽度,iH 高度,TOP 头部位置,LEFT 左边位置,*/
/*      R 改变大小,S 状态栏显示,T,TB 帮助显示*/
/*返回：无                                */
/******************************************/


function OWBB(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=211,";
    sF += " Height=280,";
    sF += " Top=100,";
    sF += " LEFT=600,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}

/******************************************/
/*功能：弹出窗体                          */
/*参数：URL 地址,TYPE 模式/全屏,SC 是否显示滚动条*/
/*      iW 宽度,iH 高度,TOP 头部位置,LEFT 左边位置,*/
/*      R 改变大小,S 状态栏显示,T,TB 帮助显示*/
/*返回：无                                */
/******************************************/


function OWC(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=600,";
    sF += " Height=500,";
    sF += " Top=50,";
    sF += " Left=50,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}

/******************************************/
/*功能：弹出窗体                          */
/*参数：URL 地址,TYPE 模式/全屏,SC 是否显示滚动条*/
/*      iW 宽度,iH 高度,TOP 头部位置,LEFT 左边位置,*/
/*      R 改变大小,S 状态栏显示,T,TB 帮助显示*/
/*返回：无                                */
/******************************************/
function OWM(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=1015,";
        sF += " Height=698,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=400,";
    sF += " Height=280,";
    sF += " Top=50,";
    sF += " Left=50,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}
function OWV(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=500,";
        sF += " Height=500,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=400,";
    sF += " Height=450,";
    sF += " Top=100,";
    sF += " Left=300,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}


function OWS(URL, TYPE, SC, iW, iH, TOP, LEFT, R, S, T, TB) {
    var sF = "dependent=yes,resizable=no,toolbar=no,status=no,directories=no,menubar=no,";
    var _rv;

    sF += "scrollbars=" + (SC ? SC : "NO") + ",";

    if (TYPE == "full") {
        sF += " Width=500,";
        sF += " Height=500,";
        sF += " Top=0,";
        sF += " Left=0,";
        window.open(URL, "_blank", sF, false);
        return;
    }

    //sF="dependent=yes;toolbar=no;directories=no;menubar=no;";
    sF += " Width=550,";
    sF += " Height=400,";
    sF += " Top=100,";
    sF += " Left=300,";
    //sF+="dialogTop:"+(TOP?TOP:"")+",";
    //sF+="dialogLeft:"+(LEFT?LEFT:"")+",";
    //sF+="resizable:"+(R?R:"NO")+",";
    //sF+="status:"+(S?S:"NO")+",";
    //sF+="scroll:"+(SC?SC:"NO")+",";
    //sF+="unadorned:" + (T?T:"NO") + ",";
    //sF+="help:"+(TB?TB:"NO")+",";
    //sF+="edge:sunken,";

    if (TYPE == "modal") {
        _rv = window.showModalDialog(URL, "", sF);
    }
    else {
        //window.open(URL, "_blank", "height=570, width=800, top=0, left=24, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no", false);
        window.open(URL, "_blank", sF, false);

    }
}

function maxwin() {
    moveTo(0, 0);
    resizeTo(screen.availwidth, screen.availheight);
    if (window.dialogWidth) {
        window.dialogWidth = window.screen.availWidth + "px ";
        window.dialogHeight = window.screen.availHeight + "px ";
        window.dialogTop = "0px ";
        window.dialogLeft = "0px ";
    }
    window.opener = null;
    //alert('opener1111='+window.opener);
}



/*********************************************************************************************   
/                                                   时间比较                                                   /   
/    格式必须为 yyyy-MM-dd HH:mm:SS ，或 yyyy-MM-dd ，或 MM-dd，      /   
/    或 HH:mm:SS ，或 HH:mm 。    且beginTime和endTime必须格式相同。 /   
/                                                                                      xiao@2008-01-30  /   
**********************************************************************************************/

function timeRather(beginTime, endTime) {
    var beginTemp = beginTime.split(" ");
    var endTemp = endTime.split(" ");
    // 格式判断    
    if (beginTemp[1] == null) {
        return judgement(beginTime, endTime);
    } else {
        if (beginTemp[0] == endTemp[0]) {
            return judgement(beginTemp[1], endTemp[1]);
        }
        return judgement(beginTemp[0], endTemp[0]);
    }
}

// 分解TempDate或TempTime    
function resolution(r) {
    var splitTemp = r.split("-");
    if (splitTemp[1] == null) {
        splitTemp = r.split(":");
    }
    return splitTemp;
}

// 判断方法    
function judgement(beginTime, endTime) {
    var i = 0, d1, d2;
    d1 = resolution(beginTime);
    d2 = resolution(endTime);
    for (i in d1) {
        if (d1[i] < d2[i]) {
            return true;
        }
        if (d1[i] > d2[i]) {
            return false;
        }
    }
    return false;
}


function show1(id) {/*--打开--*/
    var o = document.getElementById(id);
    o.style.display = "block";
}
function closeed1(id) {/*--关闭--*/
    var o = document.getElementById(id);
    o.style.display = "none";
}

function show2(win, id, msg) {/*--打开--*/
    var mo = win.document.getElementById("s_" + id);
    mo.innerHTML = msg;
    var o = win.document.getElementById(id);
    o.style.display = "block";
}
function closeed2(win, id) {/*--关闭--*/
    var o = win.document.getElementById(id);
    o.style.display = "none";
}

// for edit/delete records fo listview

function add_record_common(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW(url + '&customer_id=' + MassUpdate.customer_id.value, 'notfull', 'yes');
    else
        OW(url, 'notfull', 'yes');
}

function add_record_common_for_contract(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2(url + '&contract_id=' + MassUpdate.contract_id.value, 'cardframe', 'view_add_paid');
    else
        OW_LOCAL2(url, 'mainwin', 'view_add_paid');
}

function add_record_export(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2(url + '&contract_id=' + MassUpdate.contract_id.value, 'cardframe', 'view_add_export');
    else
        OW_LOCAL2(url, 'mainwin', 'view_add_export');
}

function add_record_invoice(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2(url + '&contract_id=' + MassUpdate.contract_id.value, 'cardframe', 'view_add_invoice');
    else
        OW_LOCAL2(url, 'mainwin', 'view_add_invoice');
}

function add_record_invoice2(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2(url + '&contract_id=' + MassUpdate.contract_id.value, 'cardframe', 'view_add_invoice2');
    else
        OW_LOCAL2(url, 'mainwin', 'view_add_invoice2');
}

function add_record_paid(url) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2(url + '&contract_id=' + MassUpdate.contract_id.value, 'cardframe', 'view_add_paid');
    else
        OW_LOCAL2(url, 'mainwin', 'view_add_paid');
}

function add_record_contact() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Contacts&action=AddView&type=AllContacts&customer_id=' + MassUpdate.customer_id.value, 'cardframe', 'view_add_contact');
    else
        OW_LOCAL2('/crm/index.php?module=Contacts&action=AddView&type=AllContacts', 'mainwin', 'view_add_contact');
}

function add_record_quote() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Contracts&type=Quote&action=AddView&customer_id=' + MassUpdate.customer_id.value + '&opportunity_id=' + MassUpdate.opportunity_id.value, 'cardframe', 'view_add_quote');
    else
        OW_LOCAL2('/crm/index.php?module=Contracts&type=Quote&action=AddView&customer_id=' + MassUpdate.customer_id.value, 'mainwin', 'view_add_quote');
}

function add_record_contract() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Contracts&type=Contract&action=AddView&customer_id=' + MassUpdate.customer_id.value, 'cardframe', 'view_add_contract');
    else
        OW_LOCAL2('/crm/index.php?module=Contracts&type=Contract&action=AddView&customer_id=' + MassUpdate.customer_id.value, 'mainwin', 'view_add_contract');
}

function add_record_calendar() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListCalendars&action=AddView&act_type=3&customer_id=' + MassUpdate.customer_id.value + '&opportunity_id=' + MassUpdate.opportunity_id.value, 'cardframe', 'view_add_calendar');
    else
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListCalendars&action=AddView&act_type=3', 'mainwin', 'view_add_calendar');
}


function add_record_calendar_task() {
    if (document.MassUpdate.viewtype.value == 'ViewCard') {
        parent.window.scrollTo(0, 0);
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListCalendars&action=AddView&act_type=3&customer_id=' + MassUpdate.customer_id.value + '&opportunity_id=' + MassUpdate.opportunity_id.value + '&contact_id=' + MassUpdate.contact_id.value, 'cardframe', 'view_add_calendar');
    }
    else
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListCalendars&action=AddView&act_type=3', 'mainwin', 'view_add_calendar');
}

function add_record_calendar_logs() {
    if (document.MassUpdate.viewtype.value == 'ViewCard') {
        parent.window.scrollTo(0, 0);
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListLogs&action=AddView&act_type=6&customer_id=' + MassUpdate.customer_id.value + '&opportunity_id=' + MassUpdate.opportunity_id.value + '&contact_id=' + MassUpdate.contact_id.value, 'cardframe', 'view_add_calendar');
    }
    else
        OW_LOCAL2('/crm/index.php?module=Calendars&type=ListLogs&action=AddView&act_type=6', 'mainwin', 'view_add_calendar');
}

function add_record_calendar_service() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Customers&type=Services&action=AddView&act_type=4&customer_id=' + MassUpdate.customer_id.value, 'cardframe', 'view_add_calendar');
    else
        OW_LOCAL2('/crm/index.php?module=Customers&type=Services&action=AddView&act_type=4', 'mainwin', 'view_add_calendar');
}

function add_record_calendar_advice() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Customers&type=Advices&action=AddView&act_type=5&customer_id=' + MassUpdate.customer_id.value, 'cardframe', 'view_add_calendar');
    else
        OW_LOCAL2('/crm/index.php?module=Customers&type=Advices&action=AddView&act_type=5', 'mainwin', 'view_add_calendar');
}
function add_record_sfa_event() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW('/crm/index.php?module=Calendars&type=ListSFAEvents&action=AddView&act_type=sfa&sfa_template_id=' + MassUpdate.sfa_template_id.value, 'notfull', 'yes');
    else
        OW('/crm/index.php?module=Calendars&type=ListSFAEvents&action=AddView&act_type=sfa&sfa_template_id=' + MassUpdate.cur_record_id.value, 'notfull', 'yes');
    //OW_LOCAL2('/crm/index.php?module=Calendars&type=ListSFAEvents&action=AddView&act_type=sfa&sfa_template_id='+MassUpdate.cur_record_id.value, 'mainwin', 'view_add_calendar');
}

function add_record_payment() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Expenses&type=Payment&action=AddView&customer_id=' + MassUpdate.customer_id.value + '&order_id=' + MassUpdate.order_id.value, 'cardframe', 'view_add_payment');
    else
        OW_LOCAL2('/crm/index.php?module=Expenses&type=Payment&action=AddView', 'mainwin', 'view_add_payment');
}


function add_record_import() {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?module=Buys&type=Import&action=AddView&order_id=' + MassUpdate.order_id.value, 'cardframe', 'view_add_import');
    else
        OW_LOCAL2('/crm/index.php?module=Buys&type=Import&action=AddView', 'mainwin', 'view_add_import');
}

function download_record() {
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            window.location.href = '/crm/include/moon_download.php?id=' + document.MassUpdate.elements[i].value;
            return true;
        }
    }
    alert('请勾选要下载的文件!');
    return false;
}

function export_record() {
    //alert('ok');
    window.location.href = '/crm/include/moon_export.php' + location.search;
    return true;
}

function export_record2() {
    //alert('ok');
    window.location.href = '/crm/include/moon_export.php' + location.search + '&export_type=all';
    return true;
}

function import_record() {
    switch (document.MassUpdate.module.value) {
        case 'Customers':
            OW('/crm/index.php?module=Attachments&type=ImportCustomers&action=AddView', 'notfull', 'yes');
            break;

        case 'Contacts':
            OW('/crm/index.php?module=Attachments&type=ImportContacts&action=AddView', 'notfull', 'yes');
            break;

        case 'Products':
            OW('/crm/index.php?module=Attachments&type=ImportProducts&action=AddView', 'notfull', 'yes');
            break;

        case 'Buys':
            OW('/crm/index.php?module=Attachments&type=ImportBuyCustomers&action=AddView', 'notfull', 'yes');
            break;

        default:
            alert('导入类型无法识别。');
            break;
    }
}

function edit_record(url_para) {
    //alert('edit_contact');
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert("name = "+document.MassUpdate.elements[i].name);
        //alert("checked = "+document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            //alert("value = "+document.MassUpdate.elements[i].value);
            //OW('/crm/index.php?action=EditView&module=Contacts&customer_id={CUSTOMER_ID}&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            OW('/crm/index.php?action=EditView' + url_para + '&record=' + document.MassUpdate.elements[i].value, 'notfull', 'yes');
            //OW('/crm/index.php?action=EditView&module=Customers&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            return true;
        }
    }

    alert('请勾选要编辑的记录!');
    return false;
}

function edit_record_local(url_para, from, frameid) {
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            //alert("value = "+document.MassUpdate.elements[i].value);
            //OW('/crm/index.php?action=EditView&module=Contacts&customer_id={CUSTOMER_ID}&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            OW_LOCAL2('/crm/index.php?action=EditView' + url_para + '&record=' + document.MassUpdate.elements[i].value, from, frameid);
            //OW('/crm/index.php?action=EditView&module=Customers&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            return true;
        }
    }

    alert('请勾选要编辑的记录!');
    return false;
}

function edit_record_local_new(url_para, from, frameid) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        return edit_record_local(url_para, 'cardframe', frameid);
    else
        return edit_record_local(url_para, from, frameid);
}

function edit_record2(url_para) {
    OW('/crm/index.php?action=EditView' + url_para, 'notfull', 'yes');
    return false;
}

function edit_record2_local(url_para, from, frameid) {
    OW_LOCAL2('/crm/index.php?action=EditView' + url_para, from, frameid);
    return false;
}

function edit_record2_local_new(url_para, from, frameid) {
    if (document.MassUpdate.viewtype.value == 'ViewCard')
        OW_LOCAL2('/crm/index.php?action=EditView' + url_para, 'cardframe', frameid);
    else
        OW_LOCAL2('/crm/index.php?action=EditView' + url_para, from, frameid);
    return false;
}

function detail_record2(url_para) {
    OW('/crm/index.php?action=DetailView' + url_para, 'notfull', 'yes');
    return false;
}


function handle_record_with_get(url_para) {
    //alert('edit_contact');
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert("name = "+document.MassUpdate.elements[i].name);
        //alert("checked = "+document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            //alert("value = "+document.MassUpdate.elements[i].value);
            //OW('/crm/index.php?action=EditView&module=Contacts&customer_id={CUSTOMER_ID}&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            OW(url_para + '&record=' + document.MassUpdate.elements[i].value, 'notfull', 'yes');
            //OW('/crm/index.php?action=EditView&module=Customers&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            return true;
        }
    }

    alert('请勾选要编辑的记录!');
    return false;
}

function handle_record2_with_get(url_para) {
    OW(url_para, 'notfull', 'yes');
    return false;
}

function delete_records() {
    //alert('delete_customers');
    var flag = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert(document.MassUpdate.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            flag = 1;
            break;
        }
    }

    if (flag == 0) {
        alert('请勾选要删除的记录!');
        return false;
    }
    if (confirm('确定要删除所选择的记录吗?')) {
        document.MassUpdate.submit();
        return true;
    }
    else return false;
}

function delete_record() {
    if (confirm('确定要删除此记录吗?')) {
        MassUpdate.action.value = 'DeleteCur';
        MassUpdate.submit();
        return true;
    }
    else return false;
}

function delete_record2() {
    if (confirm('确定要删除此记录吗?')) {
        window.location = '/crm/index.php?module=' + EditView.module.value
				+ '&type=' + EditView.type.value
				+ '&action=DeleteCur'
				+ '&cur_record_id=' + EditView.record.value
				+ '&return_action=RefreshParent';
        return false;
    }
    else return false;
}

function handle_records(action) {
    //alert('handle_records');
    var flag = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert(document.MassUpdate.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
					&& (document.MassUpdate.elements[i].checked == true)) {
            flag = 1;
            break;
        }
    }

    if (flag == 0) {
        alert('请选择要' + action + '的记录!');
        return false;
    }
    if (confirm('确定要' + action + '所选择的记录吗?')) {
        MassUpdate.submit();
        return true;
    }
    else return false;
}

function handle_record(action) {
    //alert('handle_records');
    if (confirm('确定要' + action + '此记录吗?')) {
        MassUpdate.submit();
        return true;
    }
    else return false;
}

function checkAll(form, field, value) {
    //alert("checkAll");
    for (i = 0; i < form.elements.length; i++) {
        if (form.elements[i].name == field)
            form.elements[i].checked = value;
    }
}

/*****************************for ajax*************************/
function xmlGet(url) {
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var linkurl = url;
    http_request.open("GET", linkurl, false);
    http_request.send(null);
    return http_request.responseText;
}

function xmlGet_ASYN(url, result_func) {
    /*
    if(window.XMLHttpRequest){
    http_request=new XMLHttpRequest();
    }else if(window.ActiveXObject){
    http_request=new ActiveXObject("Microsoft.XMLHTTP");
    }
    */
    if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) { }
        }
    }
    /*
    else if(window.ActiveXObject){
    http_request = new ActiveXObject("Msxml2.XMLHTTP.4.0");
    }else if(window.ActiveXObject){
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }*/
    else if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    }
    var linkurl = url;
    http_request.open("GET", linkurl, true);
    http_request.send(null);
    //return http_request.responseText;
    http_request.onreadystatechange = function () {
        if (4 == http_request.readyState) {
            if (200 == http_request.status) {
                result_func(http_request.responseText);
                /*	
                //alert('ok');
                //alert(http_request.responseText);
                var array=http_request.responseText.split('=');

                var curid = 'check'+array[0];
                if (array[1] == 'RESULT_OK')
                document.getElementById(curid).innerHTML = '<img src="https://www.mooncrm.com/crm/image/right_icon.gif">';//'<table><td><img src="https://www.mooncrm.com/crm/image/err_icon.gif"></td><td><FONT color=red>该企业代码已存在</FONT></td></table>';//'<img src="https://www.mooncrm.com/crm/image/right_icon.gif">';// + http_request.responseText;
                else
                document.getElementById(curid).innerHTML = '<table><td><img src="https://www.mooncrm.com/crm/image/err_icon.gif"></td><td><FONT color=red>'+array[1]+'</FONT></td></table>';//'<img src="https://www.mooncrm.com/crm/image/right_icon.gif">';// + http_request.responseText;
                //document.getElementById("checkcompname").innerHTML = '<img src="https://www.mooncrm.com/crm/image/right_icon.gif">';//'<table><td><img src="https://www.mooncrm.com/crm/image/err_icon.gif"></td><td><FONT color=red>该企业代码已存在</FONT></td></table>';//'<img src="https://www.mooncrm.com/crm/image/right_icon.gif">';// + http_request.responseText;
				
                //checkcompno111.innerhtml = 'ok';//'<img src="https://www.mooncrm.com/crm/image/right_icon.gif" width="13" height="13">';
                */
            } else {
                //alert("发生错误!");
            }
        }
    }
}


function formToRequestString(form_id) {
    var form_obj = document.getElementById(form_id);
    var query_string = '';
    var and = '&';
    for (i = 0; i < form_obj.length; i++) {
        e = form_obj[i];
        //alert("e.name="+e.name+",e.type="+e.type+",e.value="+e.value);
        if (e.name != '') {
            if (e.type == 'select-one') {
                element_value = e.options[e.selectedIndex].value;
            } else if (e.type == 'checkbox' || e.type == 'radio') {
                if (e.checked == false) {
                    continue;
                } element_value = e.value;
            } else {
                element_value = e.value;
            }
            query_string += and + e.name + '=' + escape(element_value);
        }
    }
    return query_string;
}

function xmlPost(url, form_id) {
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    var linkurl = url;
    var data = formToRequestString(form_id);
    http_request.open("POST", linkurl, false);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); //'application/x-www-form-urlencoded');
    http_request.send(data);
    return http_request.responseText;
}

function submit_post(url, form, wait_dlg_id, result_script) {
    //alert('test');
    //document.getElementById(form).module.value='Test';

    show1(wait_dlg_id);
    show1('fade');
    document.getElementById('fade').style.height = document.body.scrollHeight;
    str = xmlPost(url, form);
    //alert(str);

    //closeed1(wait_dlg_id);
    if (str == 'RESULT_OK') {
        document.write(result_script);
    }
    else {
        closeed1(wait_dlg_id);
        closeed1('fade');
        alert(str);
    }
}

function show_waiting(wait_dlg_id) {
    show1(wait_dlg_id);
    show1('fade');
    document.getElementById('fade').style.height = document.body.scrollHeight;
}

function buildSelNew(url, selid, selected_str, default_index) {
    sel = document.getElementById(selid);
    sel.options.length = 0;
    str = xmlGet(url);
    selected_index = default_index;
    var str = str.replace(/\r\n/g, "")
    //alert(str+'ok');
    if (str != '') {

        array1 = str.split('@|@');
        sel.options.add(new Option('请选择', '-1'));
        for (var i = 0; i < array1.length; i++) {
            array2 = array1[i].split('@_@');
            //alert(array2[1]+'=='+selected_str+',i='+i);
            sel.options.add(new Option(array2[0], array2[1]));
            if (array2[1] == selected_str) { selected_index = i + 1; }
        }
        sel.options[selected_index].selected = true;
        //alert('selected_index='+selected_index);
        /*
        for(var k=selid+2;k<=3;k++){//更改下下级以下菜单为空
        subsel=document.getElementById('sel'+k);
        subsel.length=1;
        subsel.options[0].selected=true;
        }
        */
    }
    else {
        sel.options.add(new Option('请选择', '-1'));
        sel.options[0].selected = true;
    }
}

function buildSelNew2(url, sel, selected_str, default_index) {
    //sel=document.getElementById(selid);
    //alert(url);
    sel.options.length = 0;
    str = xmlGet(url);
    selected_index = default_index;
    //alert(str);
    if (str != '') {

        array1 = str.split('@|@');
        sel.options.add(new Option('请选择', '-1'));
        for (var i = 0; i < array1.length; i++) {
            array2 = array1[i].split('@_@');
            //alert(array2[1]+'=='+selected_str);
            sel.options.add(new Option(array2[0], array2[1]));
            if (array2[1] == selected_str) selected_index = i + 1;
        }
        sel.options[selected_index].selected = true;

        /*
        for(var k=selid+2;k<=3;k++){//更改下下级以下菜单为空
        subsel=document.getElementById('sel'+k);
        subsel.length=1;
        subsel.options[0].selected=true;
        }
        */
    }
    else {
        sel.options.add(new Option('请选择', '-1'));
        sel.options[0].selected = true;
    }
}


function show_div(id) {
    od = document.getElementById(id);

    //获得鼠标当前X,Y坐标
    var x, y;
    if (!isIE())//!document.all)
    {
        x = 100; //event.pageX;
        y = 100; //event.pageY;
    } else {
        x = document.body.scrollLeft + event.clientX; //鼠标X轴的值
        y = document.body.scrollTop + event.clientY; //鼠标Y轴的值
    }

    //window.scrollTo(100,500);//竖向滚动条位置
    od.style.display = "block";
    var sH = document.body.scrollHeight; //窗口的高度
    var sW = document.body.scrollWidth; //窗口的宽度

    var width = od.offsetWidth, height = od.offsetHeight; //设置div的大小
    //alert("width="+width+",height="+height+",sH="+sH+",sW="+sW);
    //alert("x="+x+",y="+y);
    if ((x + width) >= sW && x > width) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        x = x - width;
    }

    if ((y + height) >= sH && y > height) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        y = y - height;
    }
    //alert("x="+x+",y="+y);

    od.style.left = x;
    od.style.top = y;
    //od.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-od.offsetHeight)/2)+"px";
    //od.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-od.offsetWidth)/2)+"px";

}

function show_div_parent(id) {
    od = parent.document.getElementById(id);

    //获得鼠标当前X,Y坐标
    var x, y;
    if (!isIE())//!document.all)
    {
        x = 100; //event.pageX;
        y = 100; //event.pageY;
    } else {
        x = parent.document.body.scrollLeft + event.clientX; //鼠标X轴的值
        y = parent.document.body.scrollTop + event.clientY; //鼠标Y轴的值
    }

    //window.scrollTo(100,500);//竖向滚动条位置
    od.style.display = "block";
    var sH = parent.document.body.scrollHeight; //窗口的高度
    var sW = parent.document.body.scrollWidth; //窗口的宽度

    var width = od.offsetWidth, height = od.offsetHeight; //设置div的大小
    //alert("width="+width+",height="+height+",sH="+sH+",sW="+sW);
    //alert("x="+x+",y="+y);
    if ((x + width) >= sW && x > width) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        x = x - width;
    }

    if ((y + height) >= sH && y > height) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        y = y - height;
    }
    //alert("x="+x+",y="+y);

    od.style.left = x;
    od.style.top = y;
    //od.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-od.offsetHeight)/2)+"px";
    //od.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-od.offsetWidth)/2)+"px";

}

function show_div_choose_local(id, thiswin) {
    od = thiswin.document.getElementById(id);

    //获得鼠标当前X,Y坐标
    var x, y;
    /* 
    if(!isIE())//!document.all)
    {
    x=200;//event.pageX;
    y=200;//event.pageY;
    }else{
    x=document.body.scrollLeft+event.clientX; //鼠标X轴的值
    y=document.body.scrollTop+event.clientY; //鼠标Y轴的值
    }
    */
    x = 200;
    y = 120;

    //window.scrollTo(100,500);//竖向滚动条位置
    od.style.display = "block";
    /*
    var sH = document.body.scrollHeight; //窗口的高度
    var sW = document.body.scrollWidth; //窗口的宽度

    var width=od.offsetWidth, height=od.offsetHeight; //设置div的大小
    //alert("width="+width+",height="+height+",sH="+sH+",sW="+sW);
    //alert("x="+x+",y="+y);
    if((x + width) >= sW && x>width) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
    x = x - width;
    }
 
    if((y + height) >= sH && y>height) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
    y = y - height;
    }
    alert("x="+x+",y="+y);
    */
    od.style.left = x;
    od.style.top = y;
    //od.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-od.offsetHeight)/2)+"px";
    //od.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-od.offsetWidth)/2)+"px";

}

function show_div_full(id) {
    // od = window.top.bodyframe.mainwin.document.getElementById(id);
    od = window.top.document.getElementById(id);
    // alert('ok21');
    //获得鼠标当前X,Y坐标
    var x, y;
    if (!isIE())//!document.all)
    {
        x = 100; //event.pageX;
        y = 100; //event.pageY;
    } else {
        x = document.body.scrollLeft + event.clientX; //鼠标X轴的值
        y = document.body.scrollTop + event.clientY; //鼠标Y轴的值
    }

    x = 100;
    y = 20;

    //window.scrollTo(100,500);//竖向滚动条位置
    od.style.display = "block";
    var sH = document.body.scrollHeight; //窗口的高度
    var sW = document.body.scrollWidth; //窗口的宽度

    var width = od.offsetWidth, height = od.offsetHeight; //设置div的大小
    //alert("width="+width+",height="+height+",sH="+sH+",sW="+sW);
    //alert("x="+x+",y="+y);
    if ((x + width) >= sW && x > width) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        x = x - width;
    }

    if ((y + height) >= sH && y > height) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        y = y - height;
    }
    //alert("x="+x+",y="+y);

    od.style.left = x;
    od.style.top = y;
    //od.style.width = "1000px";
    //od.stype.pixelWidth = 1000;
    //od.stype.height = 1000;
    //od.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-od.offsetHeight)/2)+"px";
    //od.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-od.offsetWidth)/2)+"px";

}

function moon_show_div_full(id, dis_win, initx, inity) {
    od = dis_win.document.getElementById(id);

    //获得鼠标当前X,Y坐标
    var x, y;
    if (!isIE())//!document.all)
    {
        x = 100; //event.pageX;
        y = 100; //event.pageY;
    } else {
        x = document.body.scrollLeft + event.clientX; //鼠标X轴的值
        y = document.body.scrollTop + event.clientY; //鼠标Y轴的值
    }

    if (initx != -1)
        x = initx;
    if (inity != -1)
        y = inity;

    //window.scrollTo(100,500);//竖向滚动条位置
    od.style.display = "block";
    var sH = document.body.scrollHeight; //窗口的高度
    var sW = document.body.scrollWidth; //窗口的宽度

    var width = od.offsetWidth, height = od.offsetHeight; //设置div的大小
    //alert("width="+width+",height="+height+",sH="+sH+",sW="+sW);
    //alert("x="+x+",y="+y);
    if ((x + width) >= sW && x > width) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        x = x - width;
    }

    if ((y + height) >= sH && y > height) //当鼠标点击时的x坐标的值加上div的宽度大于窗口的宽度
    {
        y = y - height;
    }
    //alert("x="+x+",y="+y);

    od.style.left = x;
    od.style.top = y;
    //od.style.width = "1000px";
    //od.stype.pixelWidth = 1000;
    //od.stype.height = 1000;
    //od.style.top=(document.documentElement.scrollTop+(document.documentElement.clientHeight-od.offsetHeight)/2)+"px";
    //od.style.left=(document.documentElement.scrollLeft+(document.documentElement.clientWidth-od.offsetWidth)/2)+"px";

}

/*
function show_dlg_div_on_edit(id, frameid, url)
{
window.document.getElementById(frameid).src=url;
show_div(id);
}
*/

function show_dlg_div_on_edit(id, frameid, url) {
    window.document.getElementById(frameid).contentWindow.document.body.innerHTML = '';
    window.document.getElementById(frameid).src = url;
    show_div(id);
    if (isIE6()) //ie6 use old window
    {
        document.getElementById('fade').style.display = 'block';
        document.getElementById('fade').style.height = document.body.scrollHeight;
    }
}

function show_dlg_div_on_edit_local(from, frameid, url) {
    if (typeof (window.top.bodyframe) == "undefined") //it's normal2
    {
        return show_dlg_div_on_edit('choose', 'chooseframe', url);
    }

    view_group_id = hide_all_local_group_frm(frameid);
    //alert(view_group_id);
    if (!view_group_id) return false;

    //to show container
    //show_div_full(view_group_id); //only view for local
    show_div_choose_local(view_group_id, window.top);
    //alert('ok2');

    //to show frame
    frm = window.top.document.getElementById(frameid); //"view_add_customer");
    //alert('ok3');

    frm.style.display = "block";
    frm.contentWindow.load_init(from, url);
    window.top.cur_opener[view_group_id] = from;
    window.top.cur_url[frameid] = url;
    //alert('ok4');

    //to show fade

    switch (from) {
        case 'mainwin':
        case 'shortcuts':
        case 'choose_own_users':
            window.top.document.getElementById('fade').style.display = 'block';
            window.top.document.getElementById('fade').style.height = window.top.document.body.scrollHeight;
            break;
        default:
            break;
    }

}

function get_para_from_url(url, myname) {
    url = url.substr(url.lastIndexOf("?") + 1);
    var paramArr = url.split("&");
    for (var i = 0; i < paramArr.length; i++) {
        if (paramArr[i].indexOf(myname) != -1) {
            return (paramArr[i].split("="))[1];
        }
    }
    return "";
}

function show_popup_div(id, frameid, url) {
    //window.top.document.getElementById(frameid).style.display="none";
    show_div_full(id);

    ob = window.top.document.getElementById(frameid);
    //alert('cur frame id='+self.frameElement.id);
    //alert('parent frame id='+parent.frameElement.id);
    ob.contentWindow.document.body.innerHTML = '';

    //window.top.bodyframe.mainwin.document.getElementById(frameid).src=url;
    ob.src = url;
    //window.top.document.getElementById(frameid).style.display="block";

    //window.document.getElementById(frameid).contentWindow.document.body.innerHTML = 'test';

    //window.document.getElementById(frameid).contentWindow.document.writeln("test");

}

function get_local_frm(module, action) {
    switch (module) {
        case 'Customers':
            if (action == 'AddView')
                frm = window.top.document.getElementById("view_add_customer");
            else
                alert('此操作不支持本地资源');
            break;
        default:
            alert('此操作不支持本地资源');
            break;
    }
    return frm;
}

function hide_all_local_frm() {
    window.top.document.getElementById("view_add_customer").style.display = "none";
    window.top.document.getElementById("view_add_contact").style.display = "none";
}

function hide_all_local_group_frm(frameid) {
    switch (frameid) {
        case 'view_add_customer':
        case 'view_add_calendar':
        case 'view_detail_calendar':
        case 'view_add_contact':
        case 'view_add_quote':
        case 'view_add_contract':
        case 'view_add_export':
        case 'view_add_invoice':
        case 'view_add_paid':
        case 'view_add_customer2':
        case 'view_add_order':
        case 'view_add_import':
        case 'view_add_invoice2':
        case 'view_add_running':
        case 'view_add_travel':
        case 'view_add_cash':
        case 'view_add_payment':
        case 'view_add_msms':
        case 'view_add_email':
        case 'view_add_report':
        case 'view_add_bbs':
            window.top.document.getElementById("view_add_customer").style.display = "none";
            window.top.document.getElementById("view_add_calendar").style.display = "none";
            window.top.document.getElementById("view_detail_calendar").style.display = "none";
            window.top.document.getElementById("view_add_contact").style.display = "none";
            window.top.document.getElementById("view_add_quote").style.display = "none";
            window.top.document.getElementById("view_add_contract").style.display = "none";
            window.top.document.getElementById("view_add_export").style.display = "none";
            window.top.document.getElementById("view_add_invoice").style.display = "none";
            window.top.document.getElementById("view_add_paid").style.display = "none";
            window.top.document.getElementById("view_add_customer2").style.display = "none";
            window.top.document.getElementById("view_add_order").style.display = "none";
            window.top.document.getElementById("view_add_import").style.display = "none";
            window.top.document.getElementById("view_add_invoice2").style.display = "none";
            window.top.document.getElementById("view_add_running").style.display = "none";
            window.top.document.getElementById("view_add_travel").style.display = "none";
            window.top.document.getElementById("view_add_cash").style.display = "none";
            window.top.document.getElementById("view_add_payment").style.display = "none";
            window.top.document.getElementById("view_add_msms").style.display = "none";
            window.top.document.getElementById("view_add_email").style.display = "none";
            window.top.document.getElementById("view_add_report").style.display = "none";
            window.top.document.getElementById("view_add_bbs").style.display = "none";
            return 'view_group_add';
            break;

        case 'view_choose_user':
        case 'view_choose_product':
            window.top.document.getElementById("view_choose_user").style.display = "none";
            window.top.document.getElementById("view_choose_product").style.display = "none";
            return 'view_group_choose';

        default:
            break;
    }
    return 0;
}

function show_popup_div_local(opener_name, frameid, url) {
    module = get_para_from_url(url, 'module');
    action = get_para_from_url(url, 'action');

    //window.top.document.getElementById(frameid).style.display="none";
    show_div_full('view_local'); //only view for local
    frm = get_local_frm(module, action);
    hide_all_local_frm();

    frm.style.display = "block";
    frm.contentWindow.load_init(opener_name, url);
}


function moon_show_popup_div(id, frameid, url, dis_win, x, y) {
    moon_show_div_full(id, dis_win, x, y);
    dis_win.document.getElementById(frameid).src = url;
}

function show_dlg_div_parent(id, frameid, url) {
    window.parent.document.getElementById(frameid).src = url;
    show_div_parent(id);
}

function close_div(id) {/*--关闭--*/
    var o = window.parent.document.getElementById(id);
    o.style.display = "none";
}

function show_parent_obj(id) {
    var o = window.parent.document.getElementById(id);
    o.style.display = "block";
}

function showloading() {
    document.body.innerHTML = $('loadingDivContent').innerHTML;
    $('loading').style.display = '';
}


/******************************************/
/*功能：货币格式转换（小写-〉大写） 	  */
/*参数：需要转换的币值					  */
/*返回：大写货币						  */
/******************************************/
function convertCurrency(currencyDigits) {
    //alert("currencyDigits=="+currencyDigits);
    // alert(trim(currencyDigits)=="");
    //if (trim(currencyDigits) == "") return "";
    //alert("currencyDigits=="+currencyDigits);
    // Constants:
    var MAXIMUM_NUMBER = 99999999999.99;
    // Predefine the radix characters and currency symbols for output:
    var CN_ZERO = "零";
    var CN_ONE = "壹";
    var CN_TWO = "贰";
    var CN_THREE = "叁";
    var CN_FOUR = "肆";
    var CN_FIVE = "伍";
    var CN_SIX = "陆";
    var CN_SEVEN = "柒";
    var CN_EIGHT = "捌";
    var CN_NINE = "玖";
    var CN_TEN = "拾";
    var CN_HUNDRED = "佰";
    var CN_THOUSAND = "仟";
    var CN_TEN_THOUSAND = "万";
    var CN_HUNDRED_MILLION = "亿";
    var CN_SYMBOL = ""; //人民币
    var CN_DOLLAR = "元";
    var CN_TEN_CENT = "角";
    var CN_CENT = "分";
    var CN_INTEGER = "整";
    var CN_Negative = "负";
    // Variables:
    var integral; // Represent integral part of digit number.
    var decimal; // Represent decimal part of digit number.
    var outputCharacters; // The output result.
    var parts;
    var digits, radices, bigRadices, decimals;
    var zeroCount;
    var i, p, d;
    var quotient, modulus;

    // Validate input string:
    currencyDigits = currencyDigits.toString();

    //alert("currencyDigits=="+currencyDigits);
    if (currencyDigits == "") {
        //alert("Empty input!");
        return "";
    }
    if (currencyDigits.match(/[^-,.\d]/) != null) {
        alert("金额中包含了非法字符");
        return "";
    }
    if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
        alert("金额的数字格式不正确");
        return "";
    }

    // Normalize the format of input digits:
    currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters.
    currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning.
    // Assert the number is not greater than the maximum number.
    if (Number(currencyDigits) > MAXIMUM_NUMBER) {
        alert("输入的金额太大");
        return "";
    }

    // Process the coversion from currency digits to characters:
    // Separate integral and decimal parts before processing coversion:
    parts = currencyDigits.split(".");

    if (parts.length > 1 && parts[1] != 0) {
        integral = parts[0];
        decimal = parts[1];
        // Cut down redundant decimal digits that are after the second.
        decimal = decimal.substr(0, 2);
    }
    else {
        integral = parts[0];
        decimal = "";
    }
    // Prepare the characters corresponding to the digits:
    digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
    radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
    bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
    decimals = new Array(CN_TEN_CENT, CN_CENT);
    // Start processing:
    outputCharacters = "";
    //alert(Number(integral)==0);
    // Process integral part if it is larger than 0:
    if (Number(integral) > 0) {
        // alert("positive");
        zeroCount = 0;
        for (i = 0; i < integral.length; i++) {
            p = integral.length - i - 1;
            d = integral.substr(i, 1);
            quotient = p / 4;
            modulus = p % 4;
            if (d == "0") {
                zeroCount++;
            }
            else {
                if (zeroCount > 0) {
                    outputCharacters += digits[0];
                }
                zeroCount = 0;
                outputCharacters += digits[Number(d)] + radices[modulus];
            }
            if (modulus == 0 && zeroCount < 4) {
                outputCharacters += bigRadices[quotient];
            }
        }
        outputCharacters += CN_DOLLAR;
    } else if (Number(integral) < 0) {
        //	alert("negitive");
        zeroCount = 0;
        outputCharacters += CN_Negative;
        integral = integral.substr(1, integral.length);
        for (i = 0; i < integral.length; i++) {
            p = integral.length - i - 1;
            d = integral.substr(i, 1);
            quotient = p / 4;
            modulus = p % 4;
            if (d == "0") {
                zeroCount++;
            }
            else {
                if (zeroCount > 0) {
                    outputCharacters += digits[0];
                }
                zeroCount = 0;
                outputCharacters += digits[Number(d)] + radices[modulus];
            }
            if (modulus == 0 && zeroCount < 4) {
                outputCharacters += bigRadices[quotient];
            }
        }
        outputCharacters += CN_DOLLAR;
    }
    //alert("dddddddddddddddd");
    // Process decimal part if there is:
    if (decimal != "") {
        for (i = 0; i < decimal.length; i++) {
            d = decimal.substr(i, 1);
            if (d != "0") {
                outputCharacters += digits[Number(d)] + decimals[i];
            }
        }
    }
    // Confirm and return the final output string:
    //alert(outputCharacters);
    if (outputCharacters == "") {
        outputCharacters = CN_ZERO + CN_DOLLAR;
    }

    if (decimal == "") {
        outputCharacters += CN_INTEGER;
    }
    outputCharacters = CN_SYMBOL + outputCharacters;
    return outputCharacters;
}

function myParseFloat(value) {
    var rv = parseFloat(value);
    if (isNaN(rv)) {
        return 0;
    }
    return rv;
}

function adjust_float(obj) {
    if (obj.value == "") obj.value = "0.00";
    else {
        value = myParseFloat(obj.value);
        //alert(value);
        //alert(value.toFixed(2));
        obj.value = value.toFixed(2);
    }
}

function moon_float(num, min, max) {
    str = num.toFixed(max);
    delta = max - min;
    for (i = 0; i < delta; i++) {
        if (str.charAt(str.length - 1) == '0') {
            str = str.substr(0, str.length - 1);
        }
    }
    if (str.charAt(str.length - 1) == '.') {
        str = str.substr(0, str.length - 1);
    }
    return str;
}

function isIE() {
    return (window.navigator.userAgent.indexOf("MSIE") >= 1);
}

function isIE6() {
    return 0; //(window.navigator.userAgent.indexOf("MSIE 6.0")>=1);
}
//alert('isIE6='+isIE6());

//mooncrm v2.0
function get_now_time() {
    var nowDate = new Date();
    return nowDate.getTime();
}
function show_time(time_id) {
    obj = document.getElementById(time_id);
    var durtime = (endtime - starttime) / 1000;
    obj.innerText = durtime.toFixed(2);
}

//for corner
function setcorner(bocolor, bgcolor) {
    setcorner2(bocolor, bgcolor, bocolor);
}

function setcorner2(bocolor, bgcolor, txtbocolor) {
    //corner_table=document.all.tags("table");
    corner_table = document.getElementsByTagName("table"); //for firefox
    for (i = 0; i < corner_table.length; i++) {
        if (corner_table[i].id == "corner") {
            mycorner = corner_table[i].getElementsByTagName("A")
            corner_style = corner_table[i].className
            bo = bocolor; //"#CDE5FF";;//"#fAfCfF";//"#e8e8e8";//border
            bg = bgcolor; //"#EDF4FF";//"#EDF4FF";//"#FAFCFF";//"#EDF4FF";//"#A4CEF9";//title background color
            corner_box = corner_table[i].getElementsByTagName("TABLE")
            for (ii = 0; ii < corner_box.length; ii++)
            { if (corner_box[ii].id == "box") { corner_box = corner_box[ii]; break } }
            corner_tit = corner_box.getElementsByTagName("TR")
            for (ii = 0; ii < corner_tit.length; ii++)
            { if (corner_tit[ii].id == "tit") { corner_tit = corner_tit[ii]; break } }
            corner_tit.style.background = bg
            corner_txt = corner_box.getElementsByTagName("TD")
            for (ii = 0; ii < corner_txt.length; ii++)
            { if (corner_txt[ii].id == "txt") { corner_txt = corner_txt[ii]; break } }
            corner_txt.style.borderColor = txtbocolor;
            for (ii = 0; ii < mycorner.length; ii++) {
                //alert(mycorner[ii].id);
                if (mycorner[ii].id == "corner") {
                    postion = mycorner[ii]
                    id = mycorner[ii].className
                    if (id == "tl") { w = '3', h = '3' }
                    if (id == "tr") { w = '3', h = '3' }
                    if (id == "bl") { w = '3', h = '3' }
                    if (id == "br") { w = '3', h = '3' }
                    if (id == "t") { w = '\"100%\"', h = '3' }
                    if (id == "b") { w = '\"100%\"', h = '3' }
                    if (id == "l") { w = 3, h = corner_box.offsetHeight }
                    if (id == "r") { w = 3, h = corner_box.offsetHeight }
                    corner_ = "<td bgcolor=white></td>"
                    corner_bo = "<td bgcolor=" + bo + "></td>"
                    corner_bg = "<td bgcolor=" + bg + "></td>"
                    corner_array = [corner_, corner_bo, corner_bg]
                    if (id == "t") { col = 3; row = 1; html_array = [1, 2, 2] }   //上边
                    if (id == "b") { col = 3; row = 1; html_array = [2, 2, 1] }   //下边
                    if (id == "l") { col = 1; row = 3; html_array = [1, 2, 2] }   //左边
                    if (id == "r") { col = 1; row = 3; html_array = [2, 2, 1] }   //右边
                    if (id == "tl") { col = 3; row = 3; html_array = [0, 0, 1, 0, 1, 2, 1, 2, 2] }  //左上角
                    if (id == "tr") { col = 3; row = 3; html_array = [1, 0, 0, 2, 1, 0, 2, 2, 1] }  //右上角
                    if (id == "bl") { col = 3; row = 3; html_array = [1, 2, 2, 0, 1, 2, 0, 0, 1] }  //左下角
                    if (id == "br") { col = 3; row = 3; html_array = [2, 2, 1, 2, 1, 0, 1, 0, 0] }  //右下角
                    html = "<table style=\"font-size:0\" cellpadding=0 cellspacing=0 width=" + w + " height=" + h + "><tr>"
                    for (iii = 0; iii < html_array.length; iii++) {
                        html += corner_array[html_array[iii]]
                        if ((iii + 1) % row == 0 && (iii + 1) != html_array.length) { html += "</tr><tr>" }
                    }
                    html += "</tr></table>"
                    postion.innerHTML = html
                    //alert(id+"=\n"+html);
                }
            }
        }
    }
}

//for cookie

function Get_Sub_Cookie(name, group_name) {
    var str = Get_Cookie(group_name);
    //alert('get sub = '+str);
    if (str == null) return null;
    array1 = str.split('|');
    for (var ii = 0; ii < array1.length; ii++) {

        array2 = array1[ii].split('$');
        //alert('<get>name='+array2[0]+',value='+array2[1]);
        if (array2[0] == name) {
            return array2[1];
        }
    }
    return null;
}
function Set_Sub_Cookie(name, value, group_name) {
    var str = Get_Cookie(group_name);
    //alert('old_str='+str);
    if (str != null) {
        array1 = str.split('|');
        flag = 0;
        count = 0;
        new_str = '';
        for (var ii = 0; ii < array1.length && count < 9; ii++) {
            array2 = array1[ii].split('$');
            //alert('<set>name='+array2[0]+',value='+array2[1]);
            if (array2[0] == name) {
                continue;
            }
            new_str += '|' + array2[0] + '$' + array2[1];
            count++;
        }
        if (count)
            new_str = name + '$' + value + new_str;
        else
            new_str = name + '$' + value;
    }
    else
        new_str = name + '$' + value;
    //alert('new_str='+new_str);
    Set_Cookie(group_name, new_str);
}
function Get_Cookie(name) {
    //alert('Get_Cookie: name='+name);

    var start = document.cookie.indexOf(name + '=');
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length)))
        return null;
    if (start == -1)
        return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    //alert('Set_Cookie: name='+name+',value='+value);
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}

function Delete_Cookie(name, path, domain) {
    if (Get_Cookie(name))
        document.cookie =
      name + '=' +
      ((path) ? ';path=' + path : '') +
      ((domain) ? ';domain=' + domain : '') +
      ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

//for listview cardframe
function changeIDNull(id) {
    return;
}
function changeID(id) {
    if (id == '') return;
    //hidden last choice
    last_id = document.all.MassUpdate.cur_record_id.value;
    //alert(last_id);
    if (last_id != '')//not init detail
    {
        obj1 = document.getElementById(last_id);
        obj2 = document.getElementById(last_id + "opt");
        obj2.style.display = 'none';
        //alert(obj1.rowIndex-1);
        if ((obj1.rowIndex - 1) / 2 % 2 == 0)
            out_trodd(obj1);
        else
            out_treven(obj1);
        //obj1.style.backgroundColor=(((obj1.rowIndex-1)/2%2==0)?'#fff':'#f1f4f8');
    }

    //show current choice
    document.all.MassUpdate.cur_record_id.value = id;
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, id, 'cur_record');

    obj1 = document.getElementById(id);
    obj2 = document.getElementById(id + "opt");
    obj2.style.display = 'block';
    seleted_tr(obj1);
    //obj1.style.backgroundColor='#CFE4F9';

    //obj2.style.display='block';getElementById('optr').style.backgroundColor='#CFE4F9';this.style.backgroundColor='#CFE4F9';"

    //alert("changeID = "+id);
    //cardurl[0] = "https://www.mooncrm.com/crm/modules/email/moon_editview_email_demo.html";	
    //cardurl[1] = "https://www.mooncrm.com/crm/index.php?module=Contracts&action=test&record="+id;

    //alert(document.all.MassUpdate.module.value);
    var cardno = Get_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, 'cur_cardno');
    //var cardno = document.all.MassUpdate.cur_card_id.value;
    //alert(cardno);

    if (cardno) {
        secBoard(cardno);
    } else {
        secBoard(0);
    }
}

function changeIDCustomer(id) {
    if (id == '') return;
    //hidden last choice
    last_id = document.all.MassUpdate.cur_record_id.value;
    //alert(last_id);
    //alert('ok0');
    if (last_id != '') {
        obj1 = document.getElementById(last_id);
        obj2 = document.getElementById(last_id + "opt");
        obj2.style.display = 'none';
        //alert(obj1.rowIndex-1);
        if ((obj1.rowIndex - 1) / 2 % 2 == 0)
            out_trodd(obj1);
        else
            out_treven(obj1);
        //obj1.style.backgroundColor=(((obj1.rowIndex-1)/2%2==0)?'#fff':'#f1f4f8');
    }
    //show current choice
    document.all.MassUpdate.cur_record_id.value = id;
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, id, 'cur_record');

    obj1 = document.getElementById(id);
    obj2 = document.getElementById(id + "opt");
    obj2.style.display = 'block';
    seleted_tr(obj1);
    //obj1.style.backgroundColor='#CFE4F9';

    //obj2.style.display='block';getElementById('optr').style.backgroundColor='#CFE4F9';this.style.backgroundColor='#CFE4F9';"

    //alert("changeID = "+id);
    //cardurl[0] = "https://www.mooncrm.com/crm/modules/email/moon_editview_email_demo.html";	
    //cardurl[1] = "https://www.mooncrm.com/crm/index.php?module=Contracts&action=test&record="+id;

    //alert(document.all.MassUpdate.module.value);


    var cardno = Get_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, 'cur_cardno');
    //var cardno = document.all.MassUpdate.cur_card_id.value;
    //alert(cardno);

    if (cardno) {
        secBoardCustomer(cardno);
    } else {
        secBoardCustomer(0);
    }
}


function changeIDDetail(id) {
    if (id == '') return;
    //hidden last choice
    last_id = document.all.MassUpdate.cur_record_id.value;
    //alert(last_id);
    if (last_id != '')//not init detail
    {
        obj1 = document.getElementById(last_id);
        obj2 = document.getElementById(last_id + "opt");
        obj2.style.display = 'none';
        //alert(obj1.rowIndex-1);
        if ((obj1.rowIndex - 1) / 2 % 2 == 0)
            out_trodd(obj1);
        else
            out_treven(obj1);
        //obj1.style.backgroundColor=(((obj1.rowIndex-1)/2%2==0)?'#fff':'#f1f4f8');
    }

    //show current choice
    document.all.MassUpdate.cur_record_id.value = id;
    obj1 = document.getElementById(id);
    obj2 = document.getElementById(id + "opt");
    obj2.style.display = 'block';
    seleted_tr(obj1);
}

function secBoardNull(n) {
    return;
}

function secBoard(n) {
    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value;
    }
}

function ReSizeiFrame(iframe) {

    var FFextraHeight = 0;
    if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
        FFextraHeight = 16;
    }

    if (iframe && !window.opera) {
        iframe.style.display = "block";
        if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) {
            iframe.height = iframe.contentDocument.body.offsetHeight + FFextraHeight;
        }
        else if (iframe.Document && iframe.Document.body.scrollHeight) {
            iframe.height = iframe.Document.body.scrollHeight;
            //alert(iframe.Document.body.scrollHeight); 
        }
    }
}

function reinitIframe(frmid) {
    var iframe = document.getElementById(frmid);
    try {
        if (iframe.contentDocument && iframe.contentWindow.document.documentElement.scrollHeight) {
            iframe.height = iframe.contentWindow.document.documentElement.scrollHeight; //设置iframe在火狐下高度

        }
        else {
            var bHeight = iframe.contentWindow.document.body.scrollHeight;
            var dHeight = 360; //iframe.contentWindow.document.documentElement.scrollHeight;
            var height = Math.max(bHeight, dHeight);
            iframe.height = height;
        }
    } catch (ex) { }
}

function secBoardCustomer(n) {
    //alert(secTable.rows[0].cells.length);
    //Set_Cookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value+'cardno', n);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //alert("setboard = "+n);
    //alert(secTable.rows[0].cells.length);
    for (i = 0; i < secTable.rows[0].cells.length; i++) {
        //alert(secTable.rows[0].cells[i].className);
        secTable.rows[0].cells[i].className = "unselect" + cardwidth[i];
    }
    secTable.rows[0].cells[n].className = "selected" + cardwidth[n];
    //alert("display"+secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        //if (document.getElementsByTagName("*").MassUpdate.cur_record_id.value=='')
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value;
    }
}
function secBoardCustomerParent(n) {
    //alert(secTable.rows[0].cells.length);
    //Set_Cookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value+'cardno', n);
    Set_Sub_Cookie(parent.document.all.MassUpdate.module.value + parent.document.all.MassUpdate.type.value, n, 'cur_cardno');
    //alert("setboard = "+n);
    //alert(parent.secTable.rows[0].cells.length);
    for (i = 0; i < parent.secTable.rows[0].cells.length; i++) {
        //alert(parent.secTable.rows[0].cells[i].className);
        parent.secTable.rows[0].cells[i].className = "unselect" + parent.cardwidth[i];
    }
    //alert(parent.cardwidth[n]);
    parent.secTable.rows[0].cells[n].className = "selected" + parent.cardwidth[n];
    //alert("display"+secTable.rows[0].cells[n].style.display);
    if (parent.secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(parent.cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        //if (document.getElementsByTagName("*").MassUpdate.cur_record_id.value=='')
        if (parent.document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(parent.document.getElementById("cardframe").src);
        window.parent.document.getElementById("cardframe").src = window.parent.cardurl[n] + window.parent.document.all.MassUpdate.cur_record_id.value;
        //window.location = window.parent.document.getElementById("cardframe").src;
        //window.parent.location.reload();
    }
}

function secBoardCusStats(n) {

    //alert(secTable.rows[0].cells.length);
    //Set_Cookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value+'cardno', n);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value;
    }
}

function secBoardCusStatsCreator(n) {

    //alert(secTable.rows[0].cells.length);
    //Set_Cookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value+'cardno', n);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //alert("cur record id = "+document.all.MassUpdate.cur_record_id.value);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value;
    }
}


function secBoardProductStatsSaleNum(n) {

    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_class_id=' + document.all.MassUpdate.search_class_id.value + '&record=' + document.all.MassUpdate.cur_record_id.value;
    }
}


function secBoardOppoStatsCreator(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //alert("cur record id = "+document.all.MassUpdate.cur_record_id.value);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value + '&search_oppo_content_type=' + document.all.MassUpdate.search_oppo_content_type.value;
    }
}


function secBoardOppoStats(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_year=' + document.all.MassUpdate.search_year.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value;
    }
}

function secBoardDateYearReceivers(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_year=' + document.all.MassUpdate.search_year.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value;
    }
}

function secBoardDateReceivers(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value;
    }
}

function secBoardGoalStats(n) {

    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value + '&search_year=' + document.all.MassUpdate.search_year.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value;
    }
}

function secBoardGoalStatsSaleNumM(n) {

    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value + '&search_year=' + document.all.MassUpdate.search_year.value + '&search_class_id=' + document.all.MassUpdate.search_class_id.value;
    }
}

function secBoardOppoStatsContentType(n) {

    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value + '&search_year=' + document.all.MassUpdate.search_year.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value + '&search_oppo_content_type=' + document.all.MassUpdate.search_oppo_content_type.value;
    }
}


function secBoardMyGoalStats(n) {

    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value + '&search_year=' + document.all.MassUpdate.search_year.value;
    }
}



function secBoardContractStats(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value;
    }
}

function secBoardContractUserStats(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value;
    }
}

function secBoardContractCustomerStats(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.search_begin_date.value + '|' + document.all.MassUpdate.search_end_date.value + '&record_id=' + document.all.MassUpdate.cur_record_id.value + '&keyword=' + document.all.MassUpdate.keyword.value;
    }
}


function secBoardSearchReceivers(n) {

    //alert(secTable.rows[0].cells.length);
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, n, 'cur_cardno');
    //setCookie(document.all.MassUpdate.module.value+document.all.MassUpdate.type.value, n);
    //alert("setboard = "+n);
    for (i = 0; i < secTable.rows[0].cells.length; i++)
        secTable.rows[0].cells[i].className = "unselect";
    secTable.rows[0].cells[n].className = "selected";
    //alert(secTable.rows[0].cells[n].style.display);
    if (secTable.rows[0].cells[n].style.display != 'none') { //&sup1;·&Egrave;¨&Iuml;&THORN;
        //alert(cardurl[n]);
        //document.all.cardframe.src=cardurl[n];
        if (document.all.MassUpdate.cur_record_id.value == '')
            return;
        //alert(document.all.MassUpdate.cur_record_id.value);
        if (window.document.getElementById("cardframe").contentWindow.document.body != null)
            window.document.getElementById("cardframe").contentWindow.document.body.innerHTML = '';
        window.document.getElementById("cardframe").src = cardurl[n] + document.all.MassUpdate.cur_record_id.value + '&search_receivers_id=' + document.all.MassUpdate.search_receivers_id.value;
    }
}

function changeIDCusStats(id) {
    if (id == '') return;
    //hidden last choice
    last_id = document.all.MassUpdate.cur_record_id.value;
    //alert(last_id);
    if (last_id != '')//not init detail
    {
        obj1 = document.getElementById(last_id);
        obj2 = document.getElementById(last_id + "opt");
        obj2.style.display = 'none';
        //alert(obj1.rowIndex-1);
        if ((obj1.rowIndex - 1) / 2 % 2 == 0)
            out_trodd(obj1);
        else
            out_treven(obj1);
        //obj1.style.backgroundColor=(((obj1.rowIndex-1)/2%2==0)?'#fff':'#f1f4f8');
    }

    //show current choice
    document.all.MassUpdate.cur_record_id.value = id;
    Set_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, id, 'cur_record');

    obj1 = document.getElementById(id);
    obj2 = document.getElementById(id + "opt");
    obj2.style.display = 'block';
    seleted_tr(obj1);

    var cardno = Get_Sub_Cookie(document.all.MassUpdate.module.value + document.all.MassUpdate.type.value, 'cur_cardno');

    if (cardno) {
        secBoardCusStats(cardno);
    } else {
        secBoardCusStats(0);
    }
}


function over_tr(obj) {
    obj.style.backgroundColor = '#CFE4F9';
}

function seleted_tr(obj) {
    obj.style.backgroundColor = '#CFE4F9';
}

function out_trodd(obj) {
    obj.style.backgroundColor = '#fff';
}

function out_treven(obj) {
    obj.style.backgroundColor = '#f1f4f8';
}

//only for customers begin
function share_customers() {
    //alert('delete_customers');
    //var flag = 0;
    var recordlist = "&record_list=";
    var c = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert(document.MassUpdate.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            if (c)
                recordlist = recordlist + "," + document.MassUpdate.elements[i].value;
            else
                recordlist = recordlist + document.MassUpdate.elements[i].value;
            c++;
            //flag = 1;
            //break;
        }
    }

    if (c == 0) {
        alert('请选择要共享的记录!');
        return false;
    }
    //if (confirm('确定要删除所选择的记录吗?'))
    {
        ////closeed1('cardframe');
        //show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=User&subtype=Middle&result_action=SharedCustomers'+recordlist);
        ////show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCustomers'+recordlist);
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;
        show_dlg_div_on_edit_local('mainwin', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCustomers' + recordlist);
        return true;
    }
    //else return false;
}

function share_customer() {
    //alert('delete_customer');
    var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;

    //if (confirm('确定要删除所选择的记录吗?'))
    {
        ////closeed1('cardframe');
        ////show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCustomers'+recordlist);
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;
        show_dlg_div_on_edit_local('mainwin', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCustomers' + recordlist);

        return true;
    }
}

function share_customer2() {
    //alert('delete_customer');
    var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;

    //if (confirm('确定要删除所选择的记录吗?'))
    {
        closeed1('cardframe');
        show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCustomers' + recordlist);
        document.getElementById('fade').style.display = 'block';
        document.getElementById('fade').style.height = document.body.scrollHeight;

        return true;
    }
}

function assign_customers(to_me) {
    var recordlist = "&record_list=";
    var c = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            if (c)
                recordlist = recordlist + "," + document.MassUpdate.elements[i].value;
            else
                recordlist = recordlist + document.MassUpdate.elements[i].value;
            c++;
        }
    }

    action = to_me ? '领用' : '指派';
    if (c == 0) {
        alert('请选择要' + action + '的客户!');
        return false;
    }

    if (to_me) {
        if (confirm('确定要领用所选择的客户吗?')) {
            str = xmlGet('/crm/index.php?action=Assign&module=Customers&record_list=' + recordlist + '&to_me=1');
            if (str != 'RESULT_OK') {
                alert(str);
                return false;
            }
            window.location.reload();
            return true;
        }
    }
    else {
        ////closeed1('cardframe');
        ////show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=AssignCustomers'+recordlist);
        show_dlg_div_on_edit_local('mainwin', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=AssignCustomers' + recordlist);
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;

        return true;
    }
    return false;
}

function assign_customer(to_me) {
    var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;
    if (to_me) {
        if (confirm('确定要领用该客户吗?')) {
            str = xmlGet('/crm/index.php?action=Assign&module=Customers&record_list=' + recordlist + '&to_me=1');
            if (str != 'RESULT_OK') {
                alert(str);
                return false;
            }
            window.location.reload();
            return true;
        }
    }
    else {
        ////closeed1('cardframe');
        ////show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=AssignCustomers'+recordlist);
        show_dlg_div_on_edit_local('mainwin', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=AssignCustomers' + recordlist);
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;

        return true;
    }
}

function cancel_assign_customers(to_me) {
    var recordlist = "&record_list=";
    var c = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            if (c)
                recordlist = recordlist + "," + document.MassUpdate.elements[i].value;
            else
                recordlist = recordlist + document.MassUpdate.elements[i].value;
            c++;
        }
    }

    action = to_me ? '归还' : '收回';
    if (c == 0) {
        alert('请选择要' + action + '的客户!');
        return false;
    }

    if (confirm('确定要' + action + '所选择的客户吗?')) {
        str = xmlGet('/crm/index.php?action=CancelAssign&module=Customers&record_list=' + recordlist + '&to_me=' + to_me);
        if (str != 'RESULT_OK') {
            alert(str);
            return false;
        }
        window.location.reload();
        return true;
    }

    return false;
}

function cancel_assign_customer(to_me) {
    var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;
    action = to_me ? '归还' : '收回';
    if (confirm('确定要' + action + '该客户吗?')) {
        str = xmlGet('/crm/index.php?action=CancelAssign&module=Customers&record_list=' + recordlist + '&to_me=' + to_me);
        if (str != 'RESULT_OK') {
            alert(str);
            return false;
        }
        window.location.reload();
        return true;
    }
    return false;
}

function cancel_assign_customer_normal2(to_me) {
    var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;
    action = to_me ? '归还' : '收回';
    if (confirm('确定要' + action + '该客户吗?')) {
        str = xmlGet('/crm/index.php?action=CancelAssign&module=Customers&record_list=' + recordlist + '&to_me=' + to_me);
        if (str != 'RESULT_OK') {
            alert(str);
            return false;
        }
        if (window.opener) {
            window.opener.location.reload();
            window.opener = null;
        }
        window.open("", "_self"); window.close();
        return true;
    }
    return false;
}



//only for customers end

//for mooncrm v2.0 begin

function share_calendar() {
    //alert('share_calendar');

    //var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;

    //if (confirm('确定要删除所选择的记录吗?'))
    {
        //closeed1('cardframe');
        ////show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCalendars');
        show_dlg_div_on_edit_local('mainwin', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=SharedCalendars');
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;

        return true;
    }

}

function choose_own_users() {
    //alert('share_calendar');

    //var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;

    //if (confirm('确定要删除所选择的记录吗?'))
    {
        //closeed1('cardframe');
        //show_dlg_div_on_edit('choose', 'chooseframe', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=ChooseOwnUsers');
        show_dlg_div_on_edit_local('choose_own_users', 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=ChooseOwnUsers');
        ////document.getElementById('fade').style.display='block';
        ////document.getElementById('fade').style.height=document.body.scrollHeight;

        return true;
    }

}

function choose_own_users2() {
    //alert('share_calendar');

    //var recordlist = "&record_list=" + MassUpdate.cur_record_id.value;

    //if (confirm('确定要删除所选择的记录吗?'))
    {
        //closeed1('cardframe');
        show_dlg_div_on_edit_local(self.frameElement.id, 'view_choose_user', '/crm/index.php?module=Users&action=ListView&type=ListUsers&viewtype=ViewChoose&result_action=ChooseOwnUsers2');
        //document.getElementById('fade').style.display='block';
        //document.getElementById('fade').style.height=document.body.scrollHeight;

        return true;
    }

}



function single_handle(msg, url, reload) {
    if (msg && !confirm(msg)) return false;
    str = xmlGet(url);
    if (str != 'RESULT_OK') {
        alert(str);
        return false;
    }
    else if (reload)
        window.location.reload();
    return true;
}

function single_handles(msg, url, reload, alert_msg) {
    records = '';
    //alert(records);
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert("name = "+document.MassUpdate.elements[i].name);
        //alert("checked = "+document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            if (records == '')
                records = document.MassUpdate.elements[i].value;
            else
                records += '|' + document.MassUpdate.elements[i].value;
        }
        //alert(records);
    }
    if (records != '')
        return single_handle(msg, url + records, reload);
    else
        alert(alert_msg);
    return true;
}

function is_choosed(alert_msg) {
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            return true;
        }
    }
    if (alert_msg)
        alert(alert_msg);
    return false;
}

//防止粘贴非浮点型字符串
function paste_float() {
    //alert('ok');
    var reg = /^\-?[0-9]{0,8}\.?[0-9]{0,100}$/;
    var r = clipboardData.getData('text').match(reg);
    //alert(r);
    if (r == null) {
        //document.activeElement.value = "0.00";
        document.activeElement.focus();
        alert("粘贴的数字格式错误，请输入正确格式[如：12345678.99]");
    } else {
        document.activeElement.value = parseFloat(r).toFixed(2);
        //alert(parseFloat(r).toFixed(2));
    }
    return;
    //return "clipboardData.setData('text',clipboardData.getData('text').replace(/[^\-?[0-9]{0,8}\.?[0-9]{0,2}$]/g,''));";
}

//防止输入非整形字符
function keycheckInt() {
    var reg = /^\-?[0-9]{0,8}\.?[0-9]{0,0}$/;
    var r = document.activeElement.value.match(reg);
    var temp = document.activeElement.value;
    if (r == null) {
        //alert(temp);
        document.activeElement.value = isNaN(temp) ? '' : parseFloat(temp).toFixed(0); //inputfloat;
        //document.activeElement.value = "0.00";

        document.activeElement.focus();
        //alert("输入的数字格式错误，请输入正确格式[如：12345678.99]"); 
    } else {
        ////inputfloat = document.activeElement.value ;
    }
    //document.activeElement.value=document.activeElement.value.replace(/[^\-?[0-9]{0,8}\.?[0-9]{0,2}$]/g,'') ;
    return;
}


//防止输入非浮点字符
function keycheckFloat() {
    var reg = /^\-?[0-9]{0,16}\.?[0-9]{0,4}$/;
    var r = document.activeElement.value.match(reg);
    var temp = document.activeElement.value;
    //alert('keycheckFloat begin');
    if (r == null) {
        //alert(temp);
        document.activeElement.value = isNaN(temp) ? '' : parseFloat(temp).toFixed(4); //inputfloat;
        //document.activeElement.value = "0.00";

        document.activeElement.focus();
        //alert("输入的数字格式错误，请输入正确格式[如：12345678.99]"); 
    } else {
        ////inputfloat = document.activeElement.value ;
    }
    //document.activeElement.value=document.activeElement.value.replace(/[^\-?[0-9]{0,8}\.?[0-9]{0,2}$]/g,'') ;
    //alert('keycheckFloat end');
    return;
}

/******************************************/
/*功能：判断按键值是否有效的数字范围的值（0~9、-、.）*/
/*参数：无                                 */
/*返回：无                                 */
/******************************************/
function MaskNumber() {
    if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
|| (window.event.keyCode == 13) || (window.event.keyCode == 46)
|| (window.event.keyCode == 45))) {
        window.event.keyCode = 0;
    }
}

function check_form(formname) {
    EditView.submit();
    return true;
}

function common_check(url) {
    str = xmlGet(url);
    if (str != 'RESULT_OK') {
        alert(str);
        return false;
    }
    return true;
}

function check_import_table(tableid, form) {
    //alert('delete_customers');
    var flag = 0;
    var table_index_array = [];
    var tableindex = 0;
    var count = 0;
    for (i = 0; i < form.elements.length; i++) {
        //alert(form.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if (form.elements[i].name == "product_id[]") {
            if (form.elements[i].value != '') {
                flag = 1;
            }
        }
        else if (form.elements[i].name == "quantity[]") {
            if (form.elements[i].value != '0') {
                if (flag == 1)
                    return true;
            }
            flag = 0;
        }
    }

    alert('请至少输入一项产品，并且数量不能为0!');
    return false;
}

function check_adjust_table(tableid, form) {
    //alert('delete_customers');
    var flag = 0;
    var table_index_array = [];
    var tableindex = 0;
    var count = 0;
    for (i = 0; i < form.elements.length; i++) {
        //alert(form.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if (form.elements[i].name == "product_id[]") {
            if (form.elements[i].value != '') {
                flag = 1;
            }
        }
        else if (form.elements[i].name == "adjust_quantity[]") {
            if (form.elements[i].value != '0') {
                if (flag == 1)
                    return true;
            }
            flag = 0;
        }
    }

    alert('请至少输入一项产品，并且调整数量不能为0!');
    return false;
}

function check_quote_table(tableid, form) {
    //alert('delete_customers');
    var flag = 0;
    var table_index_array = [];
    var tableindex = 0;
    var count = 0;
    for (i = 0; i < form.elements.length; i++) {
        //alert(form.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if (form.elements[i].name == "product_id[]") {
            if (form.elements[i].value != '') {
                return true;
            }
        }
    }

    alert('请至少输入一项产品!');
    return false;
}

function relogin() {
    if (window.opener != null) {
        if (typeof (window.opener.document) == 'unknown' || typeof (window.opener.document) == 'undefined') {
            //父窗口已关闭 
            window.open('/crm/login.php');
            window.opener = null; window.open('', '_self'); window.close();
        } else {
            //父窗口没有关闭 
            window.opener.top.location.href = '/crm/login.php';
            window.opener = null; window.open('', '_self'); window.close();
        }
    }
    else {
        top.location.href = '/crm/login.php';
    }
}
function save_customer() {
    ret = true;
    document.EditView.name.value = trim(document.EditView.name.value);
    if (document.EditView.name.value == "") {
        alert("请输入客户名称!");
        document.EditView.name.focus();
        return false;
    }

    show2(window.top, 'wait_top', '正在保存客户数据...');
    str = xmlPost("https://www.mooncrm.com/crm/ajax_index.php", "EditView");
    closeed2(window.top, 'wait_top');
    if (str != 'RESULT_OK') {
        if (str.substr(0, 8) == '<script>') {
            relogin();
            return;
        }
        alert(str);
        ret = false;
    }
    else {
        //alert("module="+document.EditView.module.value+",type="+document.EditView.type.value);
        refresh_opener_local(document.EditView.module.value, document.EditView.type.value, "ListView");
        MoonCloseWinLocal('view_group_add');
    }

    return ret;
}
function check_editform(module) {
    switch (module) {
        case 'customers':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入客户名称!");
                document.EditView.name.focus();
                return false;
            }
            document.EditView.name.value = to_html3(document.EditView.name.value);
            document.EditView.description.value = to_html3(document.EditView.description.value);
            break;

        case 'calendars':
            document.EditView.subject.value = trim(document.EditView.subject.value);
            if (document.EditView.subject.value == "") {
                alert("请输入主题!");
                document.EditView.subject.focus();
                return false;
            }
            if (!check_time()) {
                //document.EditView.end_date.focus();
                return false;
            }
            document.EditView.email.value = to_html2(editor.html()); //was KE.util.getData('content1');
            break;

        case 'contacts':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入联系人姓名!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'expenses':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入费用主题!");
                document.EditView.name.focus();
                return false;
            }
            if (parseFloat(window.document.EditView.sum3.value) > parseFloat(window.document.EditView.sum2.value)) {
                alert('分列表合计金额已超过总金额!');
                return false;
            }
            show_waiting('wait');
            document.EditView.submit();
            return true;
            break;

        case 'reports':
            document.EditView.receivers_name.value = trim(document.EditView.receivers_name.value);
            if (document.EditView.receivers_name.value == "") {
                alert("请选择输入报告对象!");
                document.EditView.receivers_name.focus();
                return false;
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            document.EditView.workrecord.value = document.getElementById('detail').innerHTML;
            break;

        case 'cash':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入预支原因!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'payment':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入付款原因!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'groups':
            document.EditView.group_name.value = trim(document.EditView.group_name.value);
            if (document.EditView.group_name.value == "") {
                alert("请输入组名称!");
                document.EditView.group_name.focus();
                return false;
            }
            break;

        case 'announces':
            document.EditView.receivers_name.value = trim(document.EditView.receivers_name.value);
            if (document.EditView.receivers_name.value == "") {
                alert("请选择输入公告对象!");
                document.EditView.receivers_name.focus();
                return false;
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            break;

        case 'smss':
            document.EditView.receivers_mobile.value = trim(document.EditView.receivers_mobile.value);
            if (document.EditView.receivers_mobile.value == "") {
                alert("请选择输入接收人手机号码!");
                document.EditView.receivers_mobile.focus();
                return false;
            }
            show1('wait');
            break;

        case 'emails':
            document.EditView.receivers_email.value = trim(document.EditView.receivers_email.value);
            if (document.EditView.receivers_email.value == "") {
                alert("请填写收件人!");
                document.EditView.receivers_email.focus();
                return false;
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            show1('wait');
            break;

        case 'quotes':
            document.EditView.quote_name.value = trim(document.EditView.quote_name.value);
            if (document.EditView.quote_name.value == "") {
                alert("请填写报价名称!");
                document.EditView.quote_name.focus();
                return false;
            }

            if (!check_quote_table(ListTable, document.EditView))
                return false;
            break;

        case 'buyorders':
            document.EditView.order_name.value = trim(document.EditView.order_name.value);
            if (document.EditView.order_name.value == "") {
                alert("请填写采购订单名称!");
                document.EditView.order_name.focus();
                return false;
            }

            if (!check_quote_table(ListTable, document.EditView))
                return false;
            break;

        case 'contracts':
            document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
            if (document.EditView.contract_name.value == "") {
                alert("请填写合同名称!");
                document.EditView.contract_name.focus();
                return false;
            }
            break;

        case 'contract_paid':
            document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
            if (document.EditView.contract_name.value == "") {
                alert("请选择合同!");
                document.EditView.contract_name.focus();
                return false;
            }
            break;

        case 'invoice':
            /*
            document.EditView.title.value=trim(document.EditView.title.value);
            if(document.EditView.title.value == ""){
            alert("请填写开票内容!");
            document.EditView.title.focus();
            return false;
            }
            */

            if (typeof (document.EditView.contract_name) == "object") {
                document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
                if (document.EditView.contract_name.value == "") {
                    alert("请选择合同!");
                    document.EditView.contract_name.focus();
                    return false;
                }
            }
            else if (typeof (document.EditView.order_name) == "object") {
                document.EditView.order_name.value = trim(document.EditView.order_name.value);
                if (document.EditView.order_name.value == "") {
                    alert("请选择订单!");
                    document.EditView.order_name.focus();
                    return false;
                }
            }
            break;

        case 'order_invoice':
            /*
            document.EditView.title.value=trim(document.EditView.title.value);
            if(document.EditView.title.value == ""){
            alert("请填写发票内容!");
            document.EditView.title.focus();
            return false;
            }
            */
            document.EditView.order_name.value = trim(document.EditView.order_name.value);
            if (document.EditView.order_name.value == "") {
                alert("请选择采购订单!");
                document.EditView.order_name.focus();
                return false;
            }
            break;

        case 'products':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入产品名称!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'users':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入姓名!");
                document.EditView.name.focus();
                return false;
            }
            document.EditView.user_name.value = trim(document.EditView.user_name.value);
            if (document.EditView.user_name.value == "") {
                alert("请输入账号!");
                document.EditView.user_name.focus();
                return false;
            }
            break;

        case 'opportunitys':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入机会主题!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'export':
            if (document.EditView.contract_id.value == "") {
                alert("请选择合同!");
                return false;
            }

            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'reserved':
            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'goal':
            if (!common_check('/crm/include/moon_handle.php?module=Goals&action=pre_check&period_year=' + document.EditView.period_year.value + '&record=' + document.EditView.record.value + '&employee_id=' + document.EditView.employee_id.value))
                return false;
            break;

        case 'nettask':
            break;

        case 'import':
            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'adjust':
            if (!check_adjust_table(ListTable, document.EditView))
                return false;
            break;

        case 'import_customers':
            if (document.EditView.upload_file.value == "") {
                alert("请选择导入文件!");
                return false;
            }
            show1('wait');
            break;
        default:
            break;
    }

    EditView.submit();
    return true;
}

function check_editform_local(module) {
    switch (module) {
        case 'customers':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入客户名称!");
                document.EditView.name.focus();
                return false;
            }
            document.EditView.name.value = to_html3(document.EditView.name.value);
            document.EditView.description.value = to_html3(document.EditView.description.value);
            break;

        case 'calendars':
            document.EditView.subject.value = trim(document.EditView.subject.value);
            if (document.EditView.subject.value == "") {
                alert("请输入主题!");
                document.EditView.subject.focus();
                return false;
            }
            if (!check_time()) {
                //document.EditView.end_date.focus();
                return false;
            }
            if (editor)
                document.EditView.email.value = to_html2(editor.html()); //was KE.util.getData('content1');
            break;

        case 'contacts':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入联系人姓名!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'expenses':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入费用主题!");
                document.EditView.name.focus();
                return false;
            }
            if (parseFloat(window.document.EditView.sum3.value) > parseFloat(window.document.EditView.sum2.value)) {
                alert('分列表合计金额已超过总金额!');
                return false;
            }
            //show_waiting('wait');
            //document.EditView.submit();
            //return true;
            break;

        case 'reports':
            document.EditView.receivers_name.value = trim(document.EditView.receivers_name.value);
            if (document.EditView.receivers_name.value == "") {
                alert("请选择输入报告对象!");
                document.EditView.receivers_name.focus();
                return false;
            }

            if (document.getElementById('detail').innerHTML == "") {
                if (!confirm('此报告没有插入详细工作日志，确认要继续吗？')) {
                    return false;
                }
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            document.EditView.workrecord.value = document.getElementById('detail').innerHTML;
            break;

        case 'cash':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入预支原因!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'payment':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入付款原因!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'groups':
            document.EditView.group_name.value = trim(document.EditView.group_name.value);
            if (document.EditView.group_name.value == "") {
                alert("请输入组名称!");
                document.EditView.group_name.focus();
                return false;
            }
            break;

        case 'announces':
            document.EditView.receivers_name.value = trim(document.EditView.receivers_name.value);
            if (document.EditView.receivers_name.value == "") {
                alert("请选择输入公告对象!");
                document.EditView.receivers_name.focus();
                return false;
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            break;

        case 'smss':
            document.EditView.receivers_mobile.value = trim(document.EditView.receivers_mobile.value);
            if (document.EditView.receivers_mobile.value == "") {
                alert("请选择输入接收人手机号码!");
                document.EditView.receivers_mobile.focus();
                return false;
            }
            //show1('wait');
            break;

        case 'emails':
            document.EditView.receivers_email.value = trim(document.EditView.receivers_email.value);
            if (document.EditView.receivers_email.value == "") {
                alert("请填写收件人!");
                document.EditView.receivers_email.focus();
                return false;
            }
            document.EditView.content.value = to_html2(editor.html()); //was KE.util.getData('content1');
            //show1('wait');
            break;

        case 'quotes':
            document.EditView.quote_name.value = trim(document.EditView.quote_name.value);
            if (document.EditView.quote_name.value == "") {
                alert("请填写报价名称!");
                document.EditView.quote_name.focus();
                return false;
            }

            if (!check_quote_table(ListTable, document.EditView))
                return false;
            break;

        case 'buyorders':
            document.EditView.order_name.value = trim(document.EditView.order_name.value);
            if (document.EditView.order_name.value == "") {
                alert("请填写采购订单名称!");
                document.EditView.order_name.focus();
                return false;
            }

            if (!check_quote_table(ListTable, document.EditView))
                return false;
            break;

        case 'contracts':
            document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
            if (document.EditView.contract_name.value == "") {
                alert("请填写合同名称!");
                document.EditView.contract_name.focus();
                return false;
            }
            break;

        case 'contract_paid':
            document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
            if (document.EditView.contract_name.value == "") {
                alert("请选择合同!");
                document.EditView.contract_name.focus();
                return false;
            }
            break;

        case 'invoice':
            /*
            document.EditView.title.value=trim(document.EditView.title.value);
            if(document.EditView.title.value == ""){
            alert("请填写开票内容!");
            document.EditView.title.focus();
            return false;
            }
            */

            if (typeof (document.EditView.contract_name) == "object") {
                document.EditView.contract_name.value = trim(document.EditView.contract_name.value);
                if (document.EditView.contract_name.value == "") {
                    alert("请选择合同!");
                    document.EditView.contract_name.focus();
                    return false;
                }
            }
            else if (typeof (document.EditView.order_name) == "object") {
                document.EditView.order_name.value = trim(document.EditView.order_name.value);
                if (document.EditView.order_name.value == "") {
                    alert("请选择订单!");
                    document.EditView.order_name.focus();
                    return false;
                }
            }
            break;

        case 'order_invoice':
            /*
            document.EditView.title.value=trim(document.EditView.title.value);
            if(document.EditView.title.value == ""){
            alert("请填写发票内容!");
            document.EditView.title.focus();
            return false;
            }
            */
            document.EditView.order_name.value = trim(document.EditView.order_name.value);
            if (document.EditView.order_name.value == "") {
                alert("请选择采购订单!");
                document.EditView.order_name.focus();
                return false;
            }
            break;

        case 'products':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入产品名称!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'users':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入姓名!");
                document.EditView.name.focus();
                return false;
            }
            document.EditView.user_name.value = trim(document.EditView.user_name.value);
            if (document.EditView.user_name.value == "") {
                alert("请输入账号!");
                document.EditView.user_name.focus();
                return false;
            }
            break;

        case 'opportunitys':
            document.EditView.name.value = trim(document.EditView.name.value);
            if (document.EditView.name.value == "") {
                alert("请输入机会主题!");
                document.EditView.name.focus();
                return false;
            }
            break;

        case 'export':
            if (document.EditView.contract_id.value == "") {
                alert("请选择合同!");
                return false;
            }

            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'reserved':
            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'goal':
            if (!common_check('/crm/include/moon_handle.php?module=Goals&action=pre_check&period_year=' + document.EditView.period_year.value + '&record=' + document.EditView.record.value + '&employee_id=' + document.EditView.employee_id.value))
                return false;
            break;

        case 'nettask':
            break;

        case 'import':
            if (!check_import_table(ListTable, document.EditView))
                return false;
            break;

        case 'adjust':
            if (!check_adjust_table(ListTable, document.EditView))
                return false;
            break;

        case 'import_customers':
            if (document.EditView.upload_file.value == "") {
                alert("请选择导入文件!");
                return false;
            }
            //show1('wait');
            break;
        default:
            break;
    }

    disable_button('save_button', true);
    disable_button('save_button2', true);
    disable_button('save_button3', true);
    disable_button('save_button4', true);

    if (document.EditView.ind.value == 'ajax2') {
        EditView.submit();
        show2(window.top, 'wait_top', '正在保存...');
        return true;
    }

    ret = true;
    show2(window.top, 'wait_top', '正在保存...');

    str = xmlPost("https://www.mooncrm.com/crm/ajax_index.php", "EditView");

    handle_ajax2_result(str);
    /*
    closeed2(window.top, 'wait_top');
    if (str != 'RESULT_OK')
    {
    if (str.substr(0, 8) == '<script>')
    {
    relogin();
    return;
    }
    alert(str);
    ret = false;
    }
    else
    {
    //alert("module="+document.EditView.module.value+",type="+document.EditView.type.value);
    refresh_opener_local(document.EditView.module.value,document.EditView.type.value,"ListView");
    MoonCloseWinLocal('view_group_add');
    }
    */

    return ret;
}

function handle_ajax2_result(str) {
    closeed2(window.top, 'wait_top');
    disable_button('save_button', false);
    disable_button('save_button2', false);
    disable_button('save_button3', false);
    disable_button('save_button4', false);
    if (str != 'RESULT_OK') {
        if (str.substr(0, 8) == '<script>') {
            relogin();
            return;
        }
        alert(str);
        //ret = false;
    }
    else {
        //alert("module="+document.EditView.module.value+",type="+document.EditView.type.value);
        refresh_opener_local(document.EditView.module.value, document.EditView.type.value, "ListView");
        MoonCloseWinLocal('view_group_add');
    }
}

function disable_button(button_id, is_off) {
    obj = document.getElementById(button_id);
    if (obj) obj.disabled = is_off;
}

/*****************************************/
/*handle choose functions                */
/*****************************************/
function handle_choose_customer_for_contact(id, name) {
    window.parent.document.EditView.customer_name.value = name;
    window.parent.document.EditView.customer_id.value = id;
}

function handle_choose_customer_for_calendar(id, name) {
    window.parent.document.EditView.customer_name.value = name;
    window.parent.document.EditView.customer_id.value = id;
    buildSelNew2('/crm/include/moon_choose.php?table=contact&customer_id=' + id, parent.document.getElementById('contact_name'), '0', 0);
    obj = parent.document.getElementById('opportunity_name');
    if (obj)
        buildSelNew2('/crm/include/moon_choose.php?table=opportunity&customer_id=' + id, obj, '0', 0);
}


function handle_choose_customer_for_expense(id, name) {
    var i = window.parent.document.EditView.cur_customer_idx.value;
    window.parent.document.getElementById("row_customer_id[" + i + "]").value = id;
    window.parent.document.getElementById("row_customer[" + i + "]").value = name;

    //get user info
    str = xmlGet('/crm/include/moon_choose.php?table=employee_user&result_type=single_custom&plist=name;id;user_name&customer_id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
            /*
            if (array2[0] == 'id')
            window.parent.document.getElementById("row_user_id["+i+"]").value = array2[1];
            else if (array2[0] == 'name')
            window.parent.document.getElementById("row_user["+i+"]").value = array2[1];
            */
        }
        window.parent.document.getElementById("row_user_id[" + i + "]").value = myrow['id'];
        window.parent.document.getElementById("row_user[" + i + "]").value = myrow['name']; //myrow['user_name']+'('+myrow['name']+')';	
    }
    return true;
}

function handle_choose_customer_for_payment(id, name) {
    window.parent.document.EditView.customer_name.value = name;
    window.parent.document.EditView.customer_id.value = id;
    //alert('payee_name='+window.parent.document.EditView.payee_name.value);
    if (window.parent.document.EditView.payee_name.value == '') {
        str = xmlGet('/crm/include/moon_choose.php?table=customer&action=for_payment&customer_id=' + id);
        //alert(str);
        if (str != '') {
            array1 = str.split('&');
            for (var i = 0; i < array1.length; i++) {
                array2 = array1[i].split('=');
                //alert(array2[0]+'='+array2[1]);
                if (array2[0] == 'bank1')
                    window.parent.document.EditView.bank_name.value = array2[1];
                else if (array2[0] == 'bank1_account')
                    window.parent.document.EditView.payee_name.value = array2[1];
                else if (array2[0] == 'bank1_account_id')
                    window.parent.document.EditView.bank_code.value = array2[1];
            }
        }
    }
    return true;
}


function handle_choose_customer_for_contract(id, name) {

    window.parent.document.EditView.customer_name.value = name;
    window.parent.document.EditView.customer_id.value = id;
    buildSelNew2('/crm/include/moon_choose.php?table=contact&customer_id=' + id, parent.document.getElementById('contact_name'), '0', 0);
    buildSelNew2('/crm/include/moon_choose.php?table=opportunity&customer_id=' + id, parent.document.getElementById('opportunity_name'), '0', 0);

    str = xmlGet('/crm/include/moon_choose.php?table=customer&action=for_contract&customer_id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&');
        for (var i = 0; i < array1.length; i++) {
            array2 = array1[i].split('=');
            //alert(array2[0]+'='+array2[1]);
            if (array2[0] == 'artificial_person')
                window.parent.document.EditView.buyer_duty_person.value = array2[1];
            else if (array2[0] == 'phone')
                window.parent.document.EditView.customer_phone.value = array2[1];
            else if (array2[0] == 'email')
                window.parent.document.EditView.customer_email.value = array2[1];
            else if (array2[0] == 'fax')
                window.parent.document.EditView.customer_fax.value = array2[1];
        }
    }
    return true;
}


function handle_choose_customer(id, name, list_param, for_which) {
    switch (for_which) {
        case 'contact':
        case 'reserved':
            handle_choose_customer_for_contact(id, name);
            break;

        case 'calendar':
            handle_choose_customer_for_calendar(id, name);
            break;

        case 'quote':
            handle_choose_customer_for_calendar(id, name);
            break;

        case 'contract':
            handle_choose_customer_for_contract(id, name);
            break;

        case 'payment':
            handle_choose_customer_for_payment(id, name);
            break;

        case 'order':
            handle_choose_customer_for_calendar(id, name);
            break;

        case 'expense':
        default:
            handle_choose_customer_for_expense(id, name);
            break;
    }
    return true;
}

function handle_choose_user(id, name, list_param, for_which) {
    //alert(id);
    //alert(name);
    var i = window.parent.document.EditView.cur_customer_idx.value;
    window.parent.document.getElementById("row_user_id[" + i + "]").value = id;
    window.parent.document.getElementById("row_user[" + i + "]").value = name;
    return true;
}

function handle_choose_null(id, name, list_param, for_which) {
    return false;
}

function handle_choose_contact_for_group(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=contact&action=for_group&contact_id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        vlist['contact_id'] = id;
        vlist['name'] = to_html(myrow['name']);
        vlist['email'] = myrow['email'];
        vlist['phone_mobile'] = myrow['phone_mobile'];
        vlist['position'] = to_html(myrow['position']);
        vlist['customer_name'] = to_html(myrow['customer_name']);
        //alert(myrow['customer_name']);
        window.parent.insertRowDetail(0, vlist);
        return true;
    }
    return false;
}

function handle_choose_contact_for_email(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=contact&action=for_group&contact_id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }
        if (myrow['email'] != '') {
            if (window.parent.document.EditView.receivers_email.value != '')
                window.parent.document.EditView.receivers_email.value += ';';
            window.parent.document.EditView.receivers_email.value += myrow['email'];
        }
        return true;
    }
    return false;
}

function handle_choose_contact_for_mobile(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=contact&action=for_group&contact_id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }
        if (myrow['phone_mobile'] != '') {
            if (window.parent.document.EditView.receivers_mobile.value != '')
                window.parent.document.EditView.receivers_mobile.value += ';';
            window.parent.document.EditView.receivers_mobile.value += myrow['phone_mobile'];
        }
        return true;
    }
    return false;
}


function handle_choose_contact_for_customer(contact_id, customer_id) {
    str = xmlGet('/crm/include/moon_handle.php?module=Customers&action=add_contact&customer_id=' + customer_id + '&contact_id=' + contact_id);
    if (str != 'RESULT_OK') {
        alert(str);
        return false;
    }
    return true;
}


function handle_choose_group_for_email(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=group&action=for_email&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }
        if (myrow['name'] != '') {
            if (window.parent.document.EditView.receivers_email.value != '')
                window.parent.document.EditView.receivers_email.value += ';';
            window.parent.document.EditView.receivers_email.value += myrow['name'];
        }
        return true;
    }
    return false;
}

function handle_choose_group_for_mobile(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=group&action=for_email&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }
        if (myrow['name'] != '') {
            if (window.parent.document.EditView.receivers_mobile.value != '')
                window.parent.document.EditView.receivers_mobile.value += ';';
            window.parent.document.EditView.receivers_mobile.value += myrow['name'];
        }
        return true;
    }
    return false;
}

function handle_choose_group_for_contact(id) {
    var vlist = [];
    //get contact info
    str = xmlGet('/crm/include/moon_choose.php?table=group&action=for_email&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }
        if (myrow['name'] != '') {
            var i = window.parent.document.EditView.cur_group_idx.value;
            window.parent.document.getElementById("row_group_id[" + i + "]").value = id;
            window.parent.document.getElementById("row_group[" + i + "]").value = myrow['name'];
        }
        return true;
    }
    return false;
}


function cal_all_quote(mywin) {
    var value = 0;
    //alert(value);
    for (i = 0; i < mywin.document.EditView.elements.length; i++) {
        //alert(document.EditView.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if (mywin.document.EditView.elements[i].name == "subtotal[]") {
            value += parseFloat(mywin.document.EditView.elements[i].value);
        }
    }
    //alert(value);
    mywin.document.EditView.sum1.value = value.toFixed(2);
    obj = mywin.document.EditView.quote_price;
    if (obj) obj.value = mywin.document.EditView.sum1.value;
    obj = mywin.document.EditView.account;
    if (obj) obj.value = mywin.document.EditView.sum1.value;
}

function cal_all_contract(mywin) {
    var value = 0;
    //alert(value);
    for (i = 0; i < mywin.document.EditView.elements.length; i++) {
        //alert(document.EditView.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if (mywin.document.EditView.elements[i].name == "subtotal[]") {
            value += parseFloat(mywin.document.EditView.elements[i].value);
        }
    }
    //alert(value);
    mywin.document.EditView.sum1.value = value.toFixed(2);
    mywin.document.EditView.amount.value = mywin.document.EditView.sum1.value;
}

function handle_choose_product_for_quote(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        var i = window.parent.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        window.parent.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        window.parent.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        window.parent.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        window.parent.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = window.parent.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        window.parent.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = window.parent.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        window.parent.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        window.parent.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}


function handle_choose_product_for_quote_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = opener_win.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        opener_win.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = opener_win.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        opener_win.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        opener_win.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}


function handle_choose_product_for_contract_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = opener_win.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        opener_win.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = opener_win.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        opener_win.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        opener_win.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}


function handle_choose_product_for_invoice_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = opener_win.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        opener_win.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = opener_win.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        opener_win.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        opener_win.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}


function handle_choose_product_for_buyorder(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_buyorder&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        var i = window.parent.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        window.parent.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        window.parent.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        window.parent.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        window.parent.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = window.parent.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        window.parent.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = window.parent.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        window.parent.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        window.parent.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}

function handle_choose_product_for_buyorder_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_buyorder&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local(); //window.top.document.getElementById('view_add_contract').contentWindow;//get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        //alert('i='+i);
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        //alert(window.parent.document.getElementById("pid["+i+"]").value);
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name'];
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];

        obj = opener_win.document.getElementById("price_id[" + i + "]");
        if (obj) obj.value = myrow['public_price'];

        opener_win.document.getElementById("quantity_id[" + i + "]").value = '1';

        obj = opener_win.document.getElementById("discount_id[" + i + "]");
        if (obj) obj.value = '100';

        opener_win.document.getElementById("trade_price_id[" + i + "]").value = myrow['public_price'];
        opener_win.document.getElementById("subtotal_id[" + i + "]").value = myrow['public_price'] * 1;
        //alert('name='+window.parent.document.getElementById("name_id["+i+"]").value);
        return true;
    }
    return false;
}

function handle_choose_product_for_export(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        var i = window.parent.document.EditView.cur_product_idx.value;
        window.parent.document.getElementById("pid[" + i + "]").value = id;
        window.parent.document.getElementById("name_id[" + i + "]").value = myrow['name']; ;
        window.parent.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        window.parent.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];
        window.parent.document.getElementById("quantity_id[" + i + "]").value = '1';

        return true;
    }
    return false;
}


function handle_choose_product_for_export_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name']; ;
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];
        opener_win.document.getElementById("quantity_id[" + i + "]").value = '1';

        return true;
    }
    return false;
}


function handle_choose_product_for_adjust(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        var i = window.parent.document.EditView.cur_product_idx.value;
        window.parent.document.getElementById("pid[" + i + "]").value = id;
        window.parent.document.getElementById("name_id[" + i + "]").value = myrow['name']; ;
        window.parent.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        window.parent.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];
        window.parent.document.getElementById("quantity_id[" + i + "]").value = myrow['amount'];
        window.parent.document.getElementById("new_quantity_id[" + i + "]").value = myrow['amount'];
        window.parent.document.getElementById("adjust_quantity_id[" + i + "]").value = '0';
        return true;
    }
    return false;
}

function handle_choose_product_for_adjust_local(id) {
    var vlist = [];
    //get product info
    str = xmlGet('/crm/include/moon_choose.php?table=product&action=for_quote&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        opener_win = get_opener_local();
        var i = opener_win.document.EditView.cur_product_idx.value;
        opener_win.document.getElementById("pid[" + i + "]").value = id;
        opener_win.document.getElementById("name_id[" + i + "]").value = myrow['name']; ;
        opener_win.document.getElementById("type_id[" + i + "]").value = myrow['type'];
        opener_win.document.getElementById("unit_id[" + i + "]").value = myrow['unit'];
        opener_win.document.getElementById("quantity_id[" + i + "]").value = myrow['amount'];
        opener_win.document.getElementById("new_quantity_id[" + i + "]").value = myrow['amount'];
        opener_win.document.getElementById("adjust_quantity_id[" + i + "]").value = '0';
        return true;
    }
    return false;
}



function handle_choose_contract_for_export(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=contract&action=for_export&id=' + id);
    //alert(str);
    if (str != '') {
        window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];

            if (array2[0] == 'product') {
                //gen one product row
                array3 = myrow['product'].split('$$');
                for (var kk = 0; kk < array3.length; kk++) {
                    array4 = array3[kk].split('@@');
                    //alert(array4[0]+'='+array4[1]);
                    myrow[array4[0]] = array4[1];
                }
                vlist['product_id'] = myrow['product_id'];
                vlist['name'] = to_html(myrow['product_name']);
                vlist['type'] = to_html(myrow['product_type']);
                vlist['unit'] = myrow['unit'];
                vlist['quantity'] = myrow['quantity'];
                vlist['desc'] = myrow['description'];
                //alert(myrow['customer_name']);
                window.parent.insertRowDetail(0, vlist);
            }
        }

        //update parent input
        window.parent.document.EditView.contract_id.value = id;
        window.parent.document.EditView.contract_name.value = myrow['contract_name'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        obj = window.parent.document.getElementById("contact_name");
        if (obj) //if true, it's for export, else, it's for returns
        {
            window.parent.document.EditView.contact_phone.value = myrow['contact_phone'];
            window.parent.document.EditView.customer_address.value = myrow['customer_address'];
            window.parent.document.EditView.contact_mobile.value = myrow['contact_mobile'];
            //alert('收货人:'+window.parent.document.EditView.customer_address.value);
            buildSelNew2('/crm/include/moon_choose.php?table=contact&contract_id=' + id, window.parent.document.getElementById('contact_name'), myrow['contact_id'], 0);
        }
        return true;
    }
    return false;
}



function handle_choose_contract_for_reserved(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=contract&action=for_export&id=' + id);
    //alert(str);
    if (str != '') {
        window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];

            if (array2[0] == 'product') {
                //gen one product row
                array3 = myrow['product'].split('$$');
                for (var kk = 0; kk < array3.length; kk++) {
                    array4 = array3[kk].split('@@');
                    //alert(array4[0]+'='+array4[1]);
                    myrow[array4[0]] = array4[1];
                }
                vlist['product_id'] = myrow['product_id'];
                vlist['name'] = to_html(myrow['product_name']);
                vlist['type'] = to_html(myrow['product_type']);
                vlist['unit'] = myrow['unit'];
                vlist['quantity'] = myrow['quantity'];
                vlist['desc'] = myrow['description'];
                //alert(myrow['customer_name']);
                window.parent.insertRowDetail(0, vlist);
            }
        }

        //update parent input
        window.parent.document.EditView.contract_id.value = id;
        window.parent.document.EditView.contract_sn.value = myrow['contract_sn'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        window.parent.document.EditView.customer_id.value = myrow['customer_id'];
        return true;
    }
    return false;
}



function handle_choose_buyorder_for_import(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=buyorder&action=for_import&id=' + id);
    //alert(str);
    if (str != '') {
        window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];

            if (array2[0] == 'product') {
                //gen one product row
                array3 = myrow['product'].split('$$');
                for (var kk = 0; kk < array3.length; kk++) {
                    array4 = array3[kk].split('@@');
                    //alert(array4[0]+'='+array4[1]);
                    myrow[array4[0]] = array4[1];
                }
                vlist['product_id'] = myrow['product_id'];
                vlist['name'] = to_html(myrow['product_name']);
                vlist['type'] = to_html(myrow['product_type']);
                vlist['unit'] = myrow['unit'];
                vlist['quantity'] = myrow['quantity'];
                vlist['trade_price'] = myrow['trade_price'];
                vlist['desc'] = myrow['description'];
                sub = parseFloat(vlist['trade_price']) * parseFloat(vlist['quantity']);
                vlist['subtotal'] = moon_float(sub, 2, 4); //sub.toFixed(2);
                //alert(myrow['product_name']);
                window.parent.insertRowDetail(0, vlist);
            }
        }

        //alert(myrow['order_name']);
        //update parent input
        window.parent.document.EditView.order_id.value = id;
        window.parent.document.EditView.order_name.value = myrow['order_name'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        //window.parent.document.EditView.contact_phone.value = myrow['contact_phone'];
        //window.parent.document.EditView.customer_address.value=myrow['customer_address'];
        //window.parent.document.EditView.contact_mobile.value=myrow['contact_mobile'];
        //alert('收货人:'+window.parent.document.EditView.customer_address.value);
        //buildSelNew2('/crm/include/moon_choose.php?table=contact&contract_id='+id,window.parent.document.getElementById('contact_name'),myrow['contact_id'], 0);	
        //alert(window.parent.document.EditView.type.value);
        if (typeof (window.parent.cal_all) == 'function')
            window.parent.cal_all(window.parent);
        return true;
    }
    return false;
}

function handle_choose_buyorder_for_payment(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=buyorder&action=for_payment&id=' + id);
    //alert(str);
    if (str != '') {
        //window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //alert(myrow['order_name']);
        //update parent input
        window.parent.document.EditView.order_id.value = id;
        window.parent.document.EditView.order_sn.value = myrow['order_sn'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        window.parent.document.EditView.customer_id.value = myrow['customer_id'];
        window.parent.document.EditView.amount.value = myrow['total_price'];
        if (window.parent.document.EditView.name.value == '')
            window.parent.document.EditView.name.value = myrow['order_name'];
        if (typeof (window.parent.change_price) == 'function')
            window.parent.change_price();
        return true;
    }
    return false;
}

function handle_choose_buyorder_for_invoice_all(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=buyorder&action=for_invoice&id=' + id);
    //alert(str);
    if (str != '') {
        window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];

            if (array2[0] == 'product') {
                //gen one product row
                array3 = myrow['product'].split('$$');
                for (var kk = 0; kk < array3.length; kk++) {
                    array4 = array3[kk].split('@@');
                    //alert(array4[0]+'='+array4[1]);
                    myrow[array4[0]] = array4[1];
                }
                vlist['product_id'] = myrow['product_id'];
                vlist['name'] = to_html(myrow['product_name']);
                vlist['type'] = to_html(myrow['product_type']);
                vlist['unit'] = myrow['unit'];
                vlist['quantity'] = myrow['quantity'];
                vlist['trade_price'] = myrow['trade_price'];
                sub = parseFloat(vlist['trade_price']) * parseFloat(vlist['quantity']);
                vlist['subtotal'] = moon_float(sub, 2, 4); //sub.toFixed(2);
                //alert(myrow['product_name']);
                window.parent.insertRowDetail(0, vlist);
            }
        }

        //alert(myrow['order_name']);
        //update parent input
        window.parent.document.EditView.order_id.value = id;
        window.parent.document.EditView.order_name.value = myrow['order_name'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];

        window.parent.document.EditView.customer_addr.value = myrow['customer_addr'];
        window.parent.document.EditView.customer_phone.value = myrow['customer_phone'];
        window.parent.document.EditView.tax_id.value = myrow['tax_id'];
        window.parent.document.EditView.bank_name.value = myrow['bank_name'];
        window.parent.document.EditView.bank_account.value = myrow['bank_account'];
        window.parent.document.EditView.bank_account_id.value = myrow['bank_account_id'];

        if (typeof (window.parent.cal_all) == 'function')
            window.parent.cal_all(window.parent);
        return true;
    }
    return false;
}


function handle_choose_contract_for_invoice_new(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=contract&action=for_invoice&id=' + id);
    //alert(str);
    if (str != '') {
        window.parent.delete_all_rows();
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];

            if (array2[0] == 'product') {
                //gen one product row
                array3 = myrow['product'].split('$$');
                for (var kk = 0; kk < array3.length; kk++) {
                    array4 = array3[kk].split('@@');
                    //alert(array4[0]+'='+array4[1]);
                    myrow[array4[0]] = array4[1];
                }
                vlist['product_id'] = myrow['product_id'];
                vlist['name'] = to_html(myrow['product_name']);
                vlist['type'] = to_html(myrow['product_type']);
                vlist['unit'] = myrow['unit'];
                vlist['quantity'] = myrow['quantity'];
                vlist['trade_price'] = myrow['trade_price'];
                sub = parseFloat(vlist['trade_price']) * parseFloat(vlist['quantity']);
                vlist['subtotal'] = moon_float(sub, 2, 4); //sub.toFixed(2);
                //alert(myrow['product_name']);
                window.parent.insertRowDetail(0, vlist);
            }
        }

        window.parent.document.EditView.contract_id.value = id;
        window.parent.document.EditView.contract_name.value = myrow['contract_name'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        window.parent.document.EditView.customer_addr.value = myrow['customer_addr'];
        window.parent.document.EditView.customer_phone.value = myrow['customer_phone'];
        window.parent.document.EditView.tax_id.value = myrow['tax_id'];
        window.parent.document.EditView.bank_name.value = myrow['bank_name'];
        window.parent.document.EditView.bank_account.value = myrow['bank_account'];
        window.parent.document.EditView.bank_account_id.value = myrow['bank_account_id'];
        window.parent.cal_all(window.parent);
        return true;
    }
    return false;
}



function handle_choose_contract_for_invoice(id) {
    var vlist = [];
    //get contract info
    str = xmlGet('/crm/include/moon_choose.php?table=contract&action=for_export&id=' + id);
    //alert(str);
    if (str != '') {
        array1 = str.split('&&');
        var myrow = new Array();
        for (var ii = 0; ii < array1.length; ii++) {
            array2 = array1[ii].split('=');
            //alert(array2[0]+'='+array2[1]);
            myrow[array2[0]] = array2[1];
        }

        //update parent input
        window.parent.document.EditView.contract_id.value = id;
        window.parent.document.EditView.contract_name.value = myrow['contract_name'];
        window.parent.document.EditView.customer_name.value = myrow['customer_name'];
        //alert('contract_id='+window.parent.document.EditView.contract_id.value);
        return true;
    }
    return false;
}


function handle_choose_contacts(for_which) {
    //alert('handle_choose_contacts');
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    var flag = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert(document.MassUpdate.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            flag = 1;
            //alert('id='+document.MassUpdate.elements[i].value+'for_which='+for_which);
            switch (for_which) {
                case 'group':
                    handle_choose_contact_for_group(document.MassUpdate.elements[i].value);
                    break;

                case 'email':
                    handle_choose_contact_for_email(document.MassUpdate.elements[i].value);
                    break;

                case 'mobile':
                    handle_choose_contact_for_mobile(document.MassUpdate.elements[i].value);
                    break;

                case 'customer': //add existed user to customer
                    handle_choose_contact_for_customer(document.MassUpdate.elements[i].value, document.MassUpdate.which_id.value);
                    break;

                default:
                    break;
            }
            continue;
        }
    }

    if (flag == 0) {
        alert('请勾选联系人!');
        return false;
    }

    if (for_which == 'customer')
        window.parent.document.getElementById("cardframe").src = window.parent.document.getElementById("cardframe").src;
    return true;
}


function handle_choose_groups(for_which) {
    //alert('handle_choose_contacts');
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    var flag = 0;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert(document.MassUpdate.elements[i].name);
        //alert(document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            flag = 1;
            //alert('id='+document.MassUpdate.elements[i].value);
            switch (for_which) {
                case 'email':
                    handle_choose_group_for_email(document.MassUpdate.elements[i].value);
                    break;

                case 'mobile':
                    handle_choose_group_for_mobile(document.MassUpdate.elements[i].value);
                    break;

                case 'contact':
                    handle_choose_group_for_contact(document.MassUpdate.elements[i].value);
                    break;

                default:
                    break;
            }
            continue;
        }
    }

    if (flag == 0) {
        alert('请勾选联系人组!');
        return false;
    }

    return true;
}

function handle_choose_product(id, name, list_param, for_which) {
    //alert('handle_choose_product');
    //alert('for_which='+for_which);
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    switch (for_which) {
        case 'quote':
            handle_choose_product_for_quote(id);
            cal_all_quote(window.parent);
            break;

        case 'buyorder':
            handle_choose_product_for_buyorder(id);
            cal_all_quote(window.parent);
            break;

        case 'contract':
            handle_choose_product_for_quote(id);
            cal_all_contract(window.parent);
            break;

        case 'export':
            handle_choose_product_for_export(id);
            break;

        case 'adjust':
            handle_choose_product_for_adjust(id);
            break;

        case 'invoice':
            handle_choose_product_for_quote(id);
            cal_all_quote(window.parent);
            break;

        default:
            break;
    }
    { close_div('choose'); close_div('fade'); }
    return true;
}


function handle_choose_product_local(id, name, list_param, for_which) {
    //alert('handle_choose_product');
    //alert('for_which='+for_which);
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    //alert('for_which='+for_which);
    switch (for_which) {
        case 'quote':
            handle_choose_product_for_quote_local(id);
            //opener_win = window.top.document.getElementById('view_add_quote').contentWindow;
            cal_all_quote(get_opener_local());
            break;

        case 'buyorder':
            handle_choose_product_for_buyorder_local(id);
            cal_all_quote(get_opener_local());
            break;

        case 'contract':
            handle_choose_product_for_contract_local(id);
            //opener_win = window.top.document.getElementById('view_add_contract').contentWindow;
            cal_all_contract(get_opener_local());
            break;

        case 'export':
            handle_choose_product_for_export_local(id);
            break;

        case 'adjust':
            handle_choose_product_for_adjust_local(id);
            break;

        case 'invoice':
            handle_choose_product_for_invoice_local(id);
            cal_all_quote(get_opener_local());
            break;

        default:
            break;
    }
    MoonCloseWinChooseLocal('view_group_choose');
    //{close_div('choose');close_div('fade');}		
    return true;
}


function handle_choose_contract(id, name, list_param, for_which) {
    //alert('handle_choose_product');
    //alert('for_which='+for_which);
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    switch (for_which) {
        case 'invoice':
            handle_choose_contract_for_invoice(id);
            break;

        case 'export':
            handle_choose_contract_for_export(id);
            break;

        case 'reserved':
            handle_choose_contract_for_reserved(id);
            break;

        case 'invoice_all':
            handle_choose_contract_for_invoice_new(id);
            break;

        default:
            break;
    }
    { close_div('choose'); close_div('fade'); }
    return true;
}

function handle_choose_buyorder(id, name, list_param, for_which) {
    //alert('handle_choose_product');
    //alert('for_which='+for_which);
    if (document.MassUpdate.for_which.value != '')
        for_which = document.MassUpdate.for_which.value;
    switch (for_which) {
        case 'import':
        case 'invoice':
            handle_choose_buyorder_for_import(id);
            break;

        case 'invoice_all':
            handle_choose_buyorder_for_invoice_all(id);
            break;

        case 'payment':
            handle_choose_buyorder_for_payment(id);
            break;

        default:
            break;
    }
    { close_div('choose'); close_div('fade'); }
    return true;
}



function quick_search_new(search) {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    //var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var type = document.MassUpdate.elements[i].type;
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            //alert('value='+value+',type='+type);
            if (value == 'All' && type == 'select-one') {
                var reg = new RegExp('&' + name + '=[^&]*');
                search = search.replace(reg, '');
                continue;
            }
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}


function quick_search() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    var reg3 = new RegExp('&page=[^&]*');
    while (reg3.exec(search))
        search = search.replace(reg3, '');

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var type = document.MassUpdate.elements[i].type;
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            //alert('value='+value+',type='+type);
            if (value == 'All' && type == 'select-one') {
                var reg = new RegExp('&' + name + '=[^&]*');
                search = search.replace(reg, '');
                continue;
            }
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}

function full_search() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    //alert('full_search begin');
    //alert('url='+location.href);
    var search = location.search;
    //var search = '?module=Customers&action=ListView&type=MyCustomers&full_search=1';//window.opener.location.search;
    var reg1 = new RegExp('&action=SearchView');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
    }
    search += '&action=ListView&full_search=1';
    //alert('parent.document.MassUpdate.elements.length = '+parent.document.MassUpdate.elements.length);
    for (i = 0; i < document.EditView.elements.length; i++) {
        if (document.EditView.elements[i].name.substring(0, 7) == 'search_') {
            var name = document.EditView.elements[i].name;
            var value = document.EditView.elements[i].value;
            if (value == 'All'
				|| value == 'NotSetCity'
				|| value == 'NotSetCountry'
				|| value == 'NotSetState'
				|| value == 'Not_set'
				|| value == 'NotSet') continue;
            search += '&' + name + '=' + value;
        }
    }
    //alert('search='+search);
    if (isIE6())
        window.opener.location.href = '/crm/index.php' + search;
    else
        get_opener().location.href = '/crm/index.php' + search;

    return true;
}

function quick_search_approve() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    var reg3 = new RegExp('&page=[^&]*');
    while (reg3.exec(search))
        search = search.replace(reg3, '');

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            /*
            if (value == 'All' || value == '')
            {
            continue;
            }
            */
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    search = search.replace(/&apply_status=[^&]*/, '');
    search = search.replace(/&apply_type=[^&]*/, '');
    //search=search.replace(/&apply_period=[^&]*/, '');
    search += '&apply_status=' + document.MassUpdate.apply_status.value
					+ '&apply_type=' + document.MassUpdate.apply_type.value;
    //+'&apply_period='+document.MassUpdate.apply_period.value;

    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}

function quick_search_running() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    var reg3 = new RegExp('&page=[^&]*');
    while (reg3.exec(search))
        search = search.replace(reg3, '');

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            //if (value == 'All' || value == '')continue;
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    search = search.replace(/&apply_status=[^&]*/, '');
    search = search.replace(/&apply_period=[^&]*/, '');
    search += '&apply_status=' + document.MassUpdate.apply_status.value
					+ '&apply_period=' + document.MassUpdate.apply_period.value;

    //alert('search='+search);
    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}

function quick_search_pay() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    var reg3 = new RegExp('&page=[^&]*');
    while (reg3.exec(search))
        search = search.replace(reg3, '');

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            /*
            if (value == 'All' || value == '')
            {
            continue;
            }
            */
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    ////search=search.replace(/&apply_status=[^&]*/, '');
    ////search=search.replace(/&apply_type=[^&]*/, '');
    //search=search.replace(/&apply_period=[^&]*/, '');
    /*search += '&apply_status='+document.MassUpdate.apply_status.value
    +'&apply_type='+document.MassUpdate.apply_type.value;
    //+'&apply_period='+document.MassUpdate.apply_period.value;
    */
    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}


function quick_search_home() {
    switch (document.MassUpdate.search_module.value) {
        case 'customer':
            module = 'Customers';
            type = 'MyCustomers';
            break;

        case 'contact':
            module = 'Contacts';
            type = 'AllContacts';
            break;

        case 'activity':
            module = 'Calendars';
            type = 'ListCalendars';
            break;

        case 'quote':
            module = 'Contracts';
            type = 'Quote';
            break;

        case 'contract':
            module = 'Contracts';
            type = 'Contract';
            break;

        case 'export':
            module = 'Contracts';
            type = 'Export';
            break;

        case 'paid':
            module = 'Contracts';
            type = 'Paid';
            break;

        case 'invoice':
            module = 'Contracts';
            type = 'Invoice';
            break;

        default:
            module = 'Homes';
            type = 'Home';
            break;
    }

    url = '/crm/index.php?module=' + module + '&type=' + type + '&action=ListView&keyword=' + document.MassUpdate.keyword.value;
    //alert(url);
    location.href = url;
    return;
}


function quick_search_storage_flows() {
    //var reg=/action=[^&]+/;
    //alert(reg.exec(location.href));
    var search = location.search;

    //clear full search item
    var reg1 = new RegExp('&full_search=1');
    if (reg1.exec(search)) {

        //alert(search);
        search = search.replace(reg1, '');
        //alert(search);
        var reg2 = new RegExp('&search_[^=]*=[^&]*');
        while (reg2.exec(search))
            search = search.replace(reg2, '');
        //alert(search);
    }

    var reg3 = new RegExp('&page=[^&]*');
    while (reg3.exec(search))
        search = search.replace(reg3, '');

    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        if (document.MassUpdate.elements[i].name.substring(0, 7) == 'search_' || document.MassUpdate.elements[i].name == 'keyword') {
            var name = document.MassUpdate.elements[i].name;
            var value = document.MassUpdate.elements[i].value;
            /*
            if (value == 'All' || value == '')
            {
            continue;
            }
            */
            var reg = new RegExp(name + '=[^&]*');
            //alert('reg='+reg.exec(search));
            if (reg.exec(search)) {
                search = search.replace(reg, name + '=' + value);
            }
            else {
                search += '&' + name + '=' + value;
            }
            //alert('name='+document.MassUpdate.elements[i].name+',value='+document.MassUpdate.elements[i].value);
        }
    }
    search = search.replace(/&apply_type=[^&]*/, '');
    //search=search.replace(/&apply_period=[^&]*/, '');
    search += '&apply_type_storage=' + document.MassUpdate.apply_type_storage.value;
    //+'&apply_period='+document.MassUpdate.apply_period.value;

    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}


function change_goal_period_type() {
    //alert(document.MassUpdate.period_type.value);
    if (document.MassUpdate.period_type.value == '0') //per month
    {
        quick_search_new('?module=GoalStats&type=' + document.MassUpdate.type.value.substr(0, document.MassUpdate.type.value.length - 1) + '&action=ListView');
    }
    else {
        quick_search_new('?module=GoalStats&type=' + document.MassUpdate.type.value + 'Q&action=ListView');
    }
}

function change_mygoal_period_type() {
    //alert(document.MassUpdate.period_type.value);
    if (document.MassUpdate.period_type.value == '0') //per month
    {
        quick_search_new('?module=Goals&type=' + document.MassUpdate.type.value.substr(0, document.MassUpdate.type.value.length - 1) + '&action=ListView');
    }
    else {
        quick_search_new('?module=Goals&type=' + document.MassUpdate.type.value + 'Q&action=ListView');
    }
}

function change_customer_period_type(tab_type) {
    //alert(document.MassUpdate.customer_period_type.value);
    if (document.MassUpdate.customer_period_type.value == '0') //per summary
    {
        quick_search_new('?module=CusStats&type=' + tab_type + '&action=ListView');
    }
    else if (document.MassUpdate.customer_period_type.value == '1') //per month
    {
        quick_search_new('?module=CusStats&type=' + tab_type + 'M&action=ListView');
    }
    else //per quarter
    {
        quick_search_new('?module=CusStats&type=' + tab_type + 'Q&action=ListView');
    }
}

function change_product_period_type(tab_type) {
    //alert(document.MassUpdate.customer_period_type.value);
    if (document.MassUpdate.customer_period_type.value == '0') //per summary
    {
        quick_search_new('?module=ProductStats&type=' + tab_type + '&action=ListView');
    }
    else if (document.MassUpdate.customer_period_type.value == '1') //per month
    {
        quick_search_new('?module=ProductStats&type=' + tab_type + 'M&action=ListView');
    }
    else //per quarter
    {
        quick_search_new('?module=ProductStats&type=' + tab_type + 'Q&action=ListView');
    }
}


function change_opportunity_period_type(tab_type) {
    //alert(document.MassUpdate.customer_period_type.value);
    if (document.MassUpdate.customer_period_type.value == '0') //per summary
    {
        quick_search_new('?module=OppoStats&type=' + tab_type + '&action=ListView');
    }
    else if (document.MassUpdate.customer_period_type.value == '1') //per month
    {
        quick_search_new('?module=OppoStats&type=' + tab_type + 'M&action=ListView');
    }
    else //per quarter
    {
        quick_search_new('?module=OppoStats&type=' + tab_type + 'Q&action=ListView');
    }
}

function change_oppo_content_type() {
    //alert(document.MassUpdate.customer_period_type.value);
    quick_search();
}



function list_sort(field_name) {
    var search = location.search;
    //alert('search1='+search);
    var reg = new RegExp('sn=' + field_name);
    if (reg.exec(search)) {
        var reg1 = new RegExp('sd=[^&]*');

        var sd = reg1.exec(search);
        //alert('sd='+sd);
        if (sd) {
            if (sd == 'sd=u')
                search = search.replace(reg1, 'sd=d');
            else
                search = search.replace(reg1, 'sd=u');
        }
        else {
            search += '&sd=u';
            //alert('search='+search);
        }
    }
    else {
        var reg2 = new RegExp('sn=[^&]*');
        //alert('reg='+reg.exec(search));
        if (reg2.exec(search)) {
            search = search.replace(reg2, 'sn=' + field_name);
        }
        else {
            search += '&' + 'sn=' + field_name;
        }
    }

    //alert('/crm/index.php'+search);
    location.href = '/crm/index.php' + search;
}

function return_today() {
    location.href = '/crm/index.php?module=Calendars&type=MyCalendars&action=ListView';
}

function quick_search_calendars() {
    if (document.MassUpdate.go_date.value == '') {
        alert('请选择要跳转的日期!');
        return;
    }
    var d = document.MassUpdate.go_date.value;
    var month = d.substring(5, d.lastIndexOf('-'));
    var day = d.substring(d.length, d.lastIndexOf('-') + 1);
    var year = d.substring(0, d.indexOf('-'));

    location.href = '/crm/index.php?module=Calendars&type=MyCalendars&action=ListView' + '&view=day&hour=0&day=' + day + '&month=' + month + '&year=' + year;
    //alert(location.href);
}

function change_view() {
    location.href = '/crm/index.php?module=Calendars&type=MyCalendars&action=ListView' + '&view=' + document.MassUpdate.view.value;
    //alert(location.href);
}


function change_calendar_status() {
    //alert('status='+document.MassUpdate.search_act_status.value);
    if (document.MassUpdate.search_act_status.value == '3') {
        //sel=document.getElementById(document.MassUpdate.search_act_period);
        document.MassUpdate.search_act_period[0].selected = true;
    }
}

function refresh_opener_OLD(module, type, action) {
    //alert('module='+module+',type='+type+',action='+action);

    var search = window.opener.location.search;
    //alert(search);
    var reg = new RegExp('module=' + module);
    var reg1 = new RegExp('type=' + type);
    var reg2 = new RegExp('viewtype=ViewCard');
    if ((reg.exec(search) && reg1.exec(search)) || reg2.exec(search)) {
        window.opener.location.reload();
    }
    else {
        window.opener.location.href = '/crm/index.php?module=' + module + '&type=' + type + '&action=' + action;
    }
}

function get_opener() {
    //alert('typeof:'+typeof(window.top.bodyframe));
    //alert('curframe:'+self.frameElement.id);
    if (typeof (window.top.bodyframe) != "undefined") {

        //normal main
        switch (self.frameElement.id) {
            case 'viewframe': //open from mainwin
                opener11 = window.top.bodyframe.mainwin;
                break;
            case 'viewframe_c': //open from mainwin.cardframe
                opener11 = window.top.bodyframe.mainwin.cardframe;
                break;
            case 'viewframe2': //open from windown.top.viewframe.chooseframe
                //opener11 = window.top.document.getElementById(parent.frameElement.id).contentWindow.document.getElementById("chooseframe").contentWindow.document;
                //opener11 = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                if (window.top.myparentframe['viewframe2'] == 'view_choose_product')
                    opener11 = window.top.document.getElementById('view_choose_product').contentWindow.document;
                else
                    opener11 = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            case 'viewframe2_c': //open from windown.top.viewframe.chooseframe
                opener11 = window.top.document.getElementById('viewframe_c').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            default:
                opener11 = window.top.bodyframe.mainwin;
                break;
        }
    }
    else {
        //normal2 main
        switch (self.frameElement.id) {
            case 'viewframe': //open from mainwin
                opener11 = window.top;
                break;
            case 'viewframe_c': //open from mainwin.cardframe
                opener11 = window.top.cardframe;
                break;
            case 'viewframe2': //open from windown.top.viewframe.chooseframe
                opener11 = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            case 'viewframe2_c': //open from windown.top.viewframe.chooseframe
                opener11 = window.top.document.getElementById('viewframe_c').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            default:
                opener11 = window.top;
                break;
        }
        //window.top.'.$refscript.';
    }
    return opener11;
}
function refresh_opener(module, type, action) {
    //alert('module='+module+',type='+type+',action='+action);
    if (isIE6()) return refresh_opener_OLD(module, type, action);

    /*
    if(typeof(window.top.bodyframe)!="undefined")
    {
    //normal main
    switch (self.frameElement.id)
    {
    case 'viewframe': //open from mainwin
    opener22 = window.top.bodyframe.mainwin;
    break;
    case 'viewframe_c': //open from mainwin.cardframe
    opener22 = window.top.bodyframe.mainwin.cardframe;
    break;
    case 'viewframe2': //open from windown.top.viewframe.chooseframe
    opener22 = window.top.document.getElementById("viewframe").contentWindow.document.getElementById("chooseframe").contentWindow.document;
    break;
    default:
    opener22 = window.top.bodyframe.mainwin;
    }
    }
    else
    {
    //normal2 main
    opener22 = window.top;
    //window.top.'.$refscript.';
    }
    */
    opener22 = get_opener();

    //opener22 = window.top.get_opener(self.frameElement.id);
    //alert('window.top.bodyframe.mainwin.name='+window.top.bodyframe.mainwin.name);
    //opener22 = window.top.document.getElementById("viewframe").contentWindow.document.getElementById("chooseframe").contentWindow.document;
    var search = opener22.location.search;
    //alert(search);
    //alert(opener22.location.href);
    var reg = new RegExp('module=' + module);
    var reg1 = new RegExp('type=' + type);
    var reg2 = new RegExp('viewtype=ViewCard');
    if ((reg.exec(search) && reg1.exec(search)) || reg2.exec(search)) {
        //alert('ok1');
        opener22.location.reload();
    }
    else {
        //alert('ok2');
        opener22.location.href = '/crm/index.php?module=' + module + '&type=' + type + '&action=' + action;
    }
}

function get_opener_local() {
    //alert('typeof:'+typeof(window.top.bodyframe));
    //alert('curframe:'+self.frameElement.id);
    if (typeof (window.top.bodyframe) != "undefined") {

        //normal main
        //alert("opener="+opener);
        switch (opener)//(self.frameElement.id)
        {
            case 'mainwin': //open from mainwin
                opener2 = window.top.bodyframe.mainwin;
                break;

            case 'viewframe': //open from frame
            case 'viewframe_c': //open from frame
            case 'view_add_calendar':
            case 'view_add_quote':
            case 'view_add_paid':
            case 'view_add_contract':
            case 'view_add_export':
            case 'view_add_invoice':
            case 'view_add_order':
            case 'view_add_import':
            case 'view_add_invoice2':
            case 'view_add_running':
            case 'view_add_travel':
            case 'view_add_cash':
            case 'view_add_payment':
            case 'view_add_report':
            case 'view_add_bbs':
                opener2 = window.top.document.getElementById(opener).contentWindow;
                break;

            case 'view_c': //open from mainwin.cardframe
            case 'cardframe':
                opener2 = window.top.bodyframe.mainwin.cardframe;
                break;

            //impossible for local as below	 
            case 'viewframe2': //open from windown.top.viewframe.chooseframe
                //opener = window.top.document.getElementById(parent.frameElement.id).contentWindow.document.getElementById("chooseframe").contentWindow.document;
                //opener = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                opener2 = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            case 'viewframe2_c': //open from windown.top.viewframe.chooseframe
                opener2 = window.top.document.getElementById('viewframe_c').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            default:
                opener2 = window.top.bodyframe.mainwin;
                break;
        }
    }
    else {
        //normal2 main
        switch (opener) {
            case 'view': //open from mainwin
                opener2 = window.top;
                break;
            case 'view_c': //open from mainwin.cardframe
                opener2 = window.top.cardframe;
                break;
            case 'viewframe2': //open from windown.top.viewframe.chooseframe
                opener2 = window.top.document.getElementById('viewframe').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            case 'viewframe2_c': //open from windown.top.viewframe.chooseframe
                opener2 = window.top.document.getElementById('viewframe_c').contentWindow.document.getElementById("chooseframe").contentWindow.document;
                break;
            default:
                opener2 = window.top;
                break;
        }
        //window.top.'.$refscript.';
    }
    return opener2;
}
function refresh_opener_local(module, type, action) {
    //alert('module='+module+',type='+type+',action='+action);
    if (isIE6()) return refresh_opener_OLD(module, type, action);


    opener = get_opener_local();

    var search = opener.location.search;
    //alert(search);
    //alert(opener.location.href);
    var reg = new RegExp('module=' + module);
    var reg1 = new RegExp('type=' + type);
    var reg2 = new RegExp('viewtype=ViewCard');
    if ((reg.exec(search) && reg1.exec(search)) || reg2.exec(search)) {
        //alert('ok1');
        opener.location.reload();
    }
    else {
        //alert('ok2');
        opener.location.href = '/crm/index.php?module=' + module + '&type=' + type + '&action=' + action;
    }
}


function listview_keydown() {
    if (event.keyCode == 13) {
        o = document.getElementById("enter");
        if (o != null) {
            o.click();
        }
        else {
            return event.srcElement.tagName == 'TEXTAREA';
        }
        return false;
    }
}

function handle_ajax_result_pageinfo(str) {
    //alert(str);
    document.getElementById('pageinfo').innerHTML = str;
}

function get_pageinfo(query_str, page, startitem, enditem) {
    url = "https://www.mooncrm.com/crm/include/moon_choose.php?" + query_str + "&table=pageinfo&page=" + page + "&startitem=" + startitem + "&enditem=" + enditem;
    xmlGet_ASYN(url, handle_ajax_result_pageinfo);
}

function handle_invoice_no_result(str) {
    document.MassUpdate.comments.value = str;
    document.MassUpdate.comments.readOnly = false;
}

function handle_invoices_no_result(str) {
    document.MassUpdate.comments_approves.value = str;
    document.MassUpdate.comments_approves.readOnly = false;
}

function get_current_invoice_no() {
    document.MassUpdate.comments.value = '';
    document.MassUpdate.comments.readOnly = true;
    //alert('/crm/include/moon_handle.php?module=Invoices&action=GetInvoiceNo&record='+MassUpdate.cur_record_id.value);
    xmlGet_ASYN('/crm/include/moon_handle.php?module=Invoices&action=GetInvoiceNo&record=' + MassUpdate.cur_record_id.value, handle_invoice_no_result);
}

function get_current_invoices_no() {
    document.MassUpdate.comments_approves.value = '';
    document.MassUpdate.comments_approves.readOnly = true;
    for (i = 0; i < document.MassUpdate.elements.length; i++) {
        //alert("name = "+document.MassUpdate.elements[i].name);
        //alert("checked = "+document.MassUpdate.elements[i].checked);
        if ((document.MassUpdate.elements[i].name == "mass[]")
				&& (document.MassUpdate.elements[i].checked == true)) {
            //OW('/crm/index.php?action=EditView'+url_para+'&record='+document.MassUpdate.elements[i].value, 'notfull', 'yes');
            xmlGet_ASYN('/crm/include/moon_handle.php?module=Invoices&action=GetInvoiceNo&record=' + document.MassUpdate.elements[i].value, handle_invoices_no_result);
            return;
        }
    }
    document.MassUpdate.comments_approves.readOnly = false;
}

function padLeft(str, lenght) {
    if (str.length >= lenght)
        return str;
    else
        return padLeft("0" + str, lenght);
}
function padRight(str, lenght) {
    if (str.length >= lenght)
        return str;
    else
        return padRight(str + "0", lenght);
}

//for tree begin
function SAll(N, S) {
    SelectAll(N);
    if (N.checked == false) {
        ///      frm.all.disabled=true;
        UnSelectSubAll(N);
    }
}
function SelectAll(N) {
    var curren = N.id;
    //checkbox的状态，选中为ture,没选为false
    var nChecked = N.checked;

    for (var i = 0; i < document.EditView.elements.length; i++) {

        var e = document.EditView.elements[i];
        if (e.type == 'checkbox') {
            var idx = e.id;
            if (idx.indexOf(curren) == 0) {
                e.checked = nChecked;
            }
        }

    }
}

function UnSelectSubAll(N) {
    var curren = N.id;
    //checkbox的状态，选中为ture,没选为false
    var nChecked = N.checked;

    for (var i = 0; i < document.EditView.elements.length; i++) {

        var e = document.EditView.elements[i];
        if (e.type == 'checkbox') {
            var idx = e.id;
            if (curren.indexOf(idx) == 0) {
                e.checked = false;
            }
        }
    }
}
function SharedCustomers(receivers_id) {
    str = xmlGet('/crm/index.php?action=Share&module=Customers&record_list=' + $_REQUEST['record_list'] + '&receivers_id=' + receivers_id);
    alert(str);
}
function save_result(name, value, num) {
    switch (result_action) {
        case 'SharedCustomers':
            str = xmlGet('/crm/index.php?action=Share&module=Customers&record_list=' + record_list + '&user_list=' + value);
            if (str != 'RESULT_OK')
                alert(str);
            show_parent_obj('cardframe');
            parent.location.reload();
            break;

        case 'AssignCustomers':
            if (num > 1) {
                alert('不能同时指派给多个用户,请选择一个用户!');
                return;
            }
            str = xmlGet('/crm/index.php?action=Assign&module=Customers&record_list=' + record_list + '&user_list=' + value);

            if (str != 'RESULT_OK') {
                alert(str);
                show_parent_obj('cardframe');
                return;
            }
            show_parent_obj('cardframe');
            parent.location.reload();
            break;

        case 'RowSingleUser':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            //alert(name);
            //handle_choose_user(value, name, '', $_REQUEST['for_witch']);
            var i = window.parent.document.EditView.cur_customer_idx.value;
            window.parent.document.getElementById("row_user_id[" + i + "]").value = value;
            window.parent.document.getElementById("row_user[" + i + "]").value = name;

            //alert(value);
            break;

        case 'EditMultiUsers':
            //alert(value);
            window.parent.document.EditView.receivers_name.value = name;
            window.parent.document.EditView.receivers_id.value = value;
            //alert(value);
            break;

        case 'SharedCalendars':
            str = xmlGet('/crm/include/moon_handle.php?action=Share&module=Calendars&user_list=' + value);
            if (str != 'RESULT_OK')
                alert(str);
            //parent.location.reload();
            break;

        case 'ChooseOwnUsers':
            window.parent.document.MassUpdate.search_receivers_name.value = name;
            window.parent.document.MassUpdate.search_receivers_id.value = value;
            break;

        case 'ChooseOwnUsers2':
            window.parent.document.EditView.search_receivers_name.value = name;
            window.parent.document.EditView.search_receivers_id.value = value;
            break;

        case 'ChooseEmployee':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            window.parent.document.EditView.employee_name.value = name;
            window.parent.document.EditView.employee_id.value = value;
            break;

        default:
            window.parent.document.EditView.receivers_name.value = name;
            window.parent.document.EditView.receivers_id.value = value;
            break;
    }
    close_div('choose');
    close_div('fade');
}

function save_result_local(name, value, num) {
    switch (result_action) {
        case 'SharedCustomers':
            str = xmlGet('/crm/index.php?action=Share&module=Customers&record_list=' + record_list + '&user_list=' + value);
            if (str != 'RESULT_OK')
                alert(str);
            ////show_parent_obj('cardframe');
            ////parent.location.reload();
            get_opener_local().location.reload();
            break;

        case 'AssignCustomers':
            if (num > 1) {
                alert('不能同时指派给多个用户,请选择一个用户!');
                return;
            }
            str = xmlGet('/crm/index.php?action=Assign&module=Customers&record_list=' + record_list + '&user_list=' + value);

            if (str != 'RESULT_OK') {
                alert(str);
                ////show_parent_obj('cardframe');
                return;
            }
            ////show_parent_obj('cardframe');
            get_opener_local().location.reload();
            break;

        case 'RowSingleUser':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            //alert(name);
            //handle_choose_user(value, name, '', $_REQUEST['for_witch']);
            opener_win = get_opener_local();
            var i = opener_win.document.EditView.cur_customer_idx.value;
            opener_win.document.getElementById("row_user_id[" + i + "]").value = value;
            opener_win.document.getElementById("row_user[" + i + "]").value = name;

            //alert(value);
            break;

        case 'EditMultiUsers':
            //alert(value);
            get_opener_local().document.EditView.receivers_name.value = name;
            get_opener_local().document.EditView.receivers_id.value = value;
            //alert(value);
            break;

        case 'SharedCalendars':
            str = xmlGet('/crm/include/moon_handle.php?action=Share&module=Calendars&user_list=' + value);
            if (str != 'RESULT_OK')
                alert(str);
            //parent.location.reload();
            break;

        case 'ChooseOwnUsers':
            ////window.parent.document.MassUpdate.search_receivers_name.value = name;
            ////window.parent.document.MassUpdate.search_receivers_id.value = value;
            window.top.bodyframe.mainwin.document.MassUpdate.search_receivers_name.value = name;
            window.top.bodyframe.mainwin.document.MassUpdate.search_receivers_id.value = value;
            break;

        case 'ChooseOwnUsers2':
            get_opener_local().document.EditView.search_receivers_name.value = name;
            get_opener_local().document.EditView.search_receivers_id.value = value;
            break;

        case 'ChooseQuotePerson':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            get_opener_local().document.EditView.quote_person_name.value = name;
            get_opener_local().document.EditView.quote_person_id.value = value;
            break;

        case 'ChooseHandleUser':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            get_opener_local().document.EditView.handle_user_name.value = name;
            get_opener_local().document.EditView.handle_user_id.value = value;
            break;

        case 'ChooseEmployee':
            if (num > 1) {
                alert('此处不能同时指定多个用户，请选择一个用户!');
                return;
            }
            get_opener_local().document.EditView.employee_name.value = name;
            get_opener_local().document.EditView.employee_id.value = value;
            break;

        default:
            get_opener_local().document.EditView.receivers_name.value = name;
            get_opener_local().document.EditView.receivers_id.value = value;
            break;
    }
    //close_div('choose');
    //close_div('fade');
    MoonCloseWinChooseLocal('view_group_choose');
}


function cancel_result() {
    if (result_action == 'SharedCustomers' || result_action == 'AssignCustomers')
        show_parent_obj('cardframe');
    close_div('choose');
    close_div('fade');
}

function getAll() {
    j = 0;
    var id = "";
    var name = "";
    var value = "";
    for (i = 0; i < document.EditView.length; i++) {
        e = document.EditView.elements[i];
        if (e.type == 'checkbox' && e.name != 'groupbox' && e.checked) {
            if (id != "") id = id + ";";
            if (name != "") name = name + "; ";
            if (value != "") value = value + ";";

            id = id + e.id;
            name = name + e.name.match(/\((\S*)\)/i)[1];
            value = value + getRealID(getRealID(e.value, "$$"), "$");
            j++;
        }
    }
    save_result(name, value, j);
}

function getAllLocal() {
    j = 0;
    var id = "";
    var name = "";
    var value = "";
    for (i = 0; i < document.EditView.length; i++) {
        e = document.EditView.elements[i];
        if (e.type == 'checkbox' && e.name != 'groupbox' && e.checked) {
            if (id != "") id = id + ";";
            if (name != "") name = name + "; ";
            if (value != "") value = value + ";";

            id = id + e.id;
            name = name + e.name.match(/\((\S*)\)/i)[1];
            value = value + getRealID(getRealID(e.value, "$$"), "$");
            j++;
        }
    }
    save_result_local(name, value, j);
}

function getAllSingle() {
    j = 0;
    var id = "";
    var name = "";
    var value = "";
    for (i = 0; i < document.EditView.length; i++) {
        e = document.EditView.elements[i];
        if (e.type == 'checkbox' && e.checked) {
            if (id != "") id = id + ";";
            if (name != "") name = name + ";";
            if (value != "") value = value + ";";
            id = id + e.id;
            name = name + e.name.match(/\((\S*)\)/i)[1];
            value = value + e.value;
            j++;
        }
    }
    parent.Picker.pick(name, value, id);
}

function getRealID(id, ssplit) {
    var checkboxid = id
    var checkboxid_array = checkboxid.split(ssplit)
    if (checkboxid_array.length == 0) {
        //alert("数组长度为0")
        return id
    }
    else {
        //alert("数组长度不为0")
        return checkboxid_array[checkboxid_array.length - 1]
    }
}

function moon_print() {
    if (confirm('确定打印吗？')) {
        //window.print();
        //printIframe.focus();   
        window.print();
    }
}

/*for kindeditor 4.0.5*/
function load_editor() {
    editor = KindEditor.create('textarea[name="content1"]',
		{
		    resizeType: 0,
		    allowPreviewEmoticons: false,
		    allowImageUpload: false,
		    items: [
			'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'cut', 'copy', 'paste',
	        'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
	        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
	        'superscript', 'clearhtml', 'quickformat', 'selectall', '/',
	        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
	        'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
	        'table', 'hr', 'emoticons', 'map', 'code', 'pagebreak',
	        'link', 'unlink', '|', 'fullscreen']
		});
}
function remove_editor() {
    if (editor) {
        editor.remove();
        editor = null;
    }
}

//for tree end
function create_shortcuts() {
    var shortcuts_list =
		'<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'1_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'1_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Customers&type=MyCustomers&action=AddView\', \'shortcuts\', \'view_add_customer\');return false;"><img src=\'/crm/themes/OA/images/Activities.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="1_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Customers&type=MyCustomers&action=AddView\', \'shortcuts\', \'view_add_customer\');return false;">新建客户</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'2_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'2_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contacts&type=AllContacts&action=AddView\', \'shortcuts\', \'view_add_contact\');return false;"><img src=\'/crm/themes/OA/images/CreateContacts.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="2_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contacts&type=AllContacts&action=AddView\', \'shortcuts\', \'view_add_contact\');return false;">新建联系人</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'3_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'3_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Calendars&type=MyCalendars&action=AddView\', \'shortcuts\', \'view_add_calendar\');return false;"><img src=\'/crm/themes/OA/images/calendar.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="3_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Calendars&type=MyCalendars&action=AddView&act_type=3\', \'shortcuts\', \'view_add_calendar\');return false;">新建日程</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'4_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'4_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Sales&type=Opportunity&action=AddView\', \'notfull\', \'yes\');return false;"><img src=\'/crm/themes/OA/images/CreateOpportunities.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="4_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Sales&type=Opportunity&action=AddView\', \'notfull\', \'yes\');return false;">新建销售机会</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'5_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'5_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Reports&type=Sent&action=AddView\', \'shortcuts\', \'view_add_report\');return false;"><img src=\'/crm/themes/OA/images/CreateReport.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="5_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Reports&type=Sent&action=AddView\', \'shortcuts\', \'view_add_report\');return false;">新建工作报告</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'6_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'6_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Quote&action=AddView\', \'shortcuts\', \'view_add_quote\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="6_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Quote&action=AddView\', \'shortcuts\', \'view_add_quote\');return false;">新建报价</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'7_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'7_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Contract&action=AddView\', \'shortcuts\', \'view_add_contract\');return false;"><img src=\'/crm/themes/OA/images/CreateContracts.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="7_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Contract&action=AddView\', \'shortcuts\', \'view_add_contract\');return false;">新建合同</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'9_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'9_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Emails&type=Sent&action=AddView\', \'shortcuts\', \'view_add_email\');return false;"><img src=\'/crm/themes/OA/images/CreateEmails.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="9_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Emails&type=Sent&action=AddView\', \'shortcuts\', \'view_add_email\');return false;">新建群发邮件</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'10_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'10_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=MSmss&type=Sent&action=AddView\', \'shortcuts\', \'view_add_msms\');return false;"><img src=\'/crm/themes/OA/images/CreateShortmessage.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="10_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=MSmss&type=Sent&action=AddView\', \'shortcuts\', \'view_add_msms\');return false;">新建群发短信</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'24_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'24_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Buys&type=Order&action=AddView\', \'shortcuts\', \'view_add_order\');return false;"><img src=\'/crm/themes/OA/images/Price_List.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="24_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Buys&type=Order&action=AddView\', \'shortcuts\', \'view_add_order\');return false;">新建采购订单</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'11_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'11_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Export&action=AddView\', \'shortcuts\', \'view_add_export\');return false;"><img src=\'/crm/themes/OA/images/Shippers.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="11_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Export&action=AddView\', \'shortcuts\', \'view_add_export\');return false;">新建发货申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'12_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'12_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Invoice&action=AddView\', \'shortcuts\', \'view_add_invoice\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="12_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Invoice&action=AddView\', \'shortcuts\', \'view_add_invoice\');return false;">新建发票</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'13_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'13_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Paid&action=AddView\', \'shortcuts\', \'view_add_paid\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="13_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Contracts&type=Paid&action=AddView\', \'shortcuts\', \'view_add_paid\');return false;">新建收款记录</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'14_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'14_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Running&action=AddView\', \'shortcuts\', \'view_add_running\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="14_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Running&action=AddView\', \'shortcuts\', \'view_add_running\');return false;">新建日常费用申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'15_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'15_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Travel&action=AddView\', \'shortcuts\', \'view_add_travel\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="15_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Travel&action=AddView\', \'shortcuts\', \'view_add_travel\');return false;">新建出差费用申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'16_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'16_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=CashAdvance&action=AddView\', \'shortcuts\', \'view_add_cash\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="16_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=CashAdvance&action=AddView\', \'shortcuts\', \'view_add_cash\');return false;">新建现金预支申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'17_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'17_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Payment&action=AddView\', \'shortcuts\', \'view_add_payment\');return false;"><img src=\'/crm/themes/OA/images/CreateQuotes.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="17_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Expenses&type=Payment&action=AddView\', \'shortcuts\', \'view_add_payment\');return false;">新建付款申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'18_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'18_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Goals&type=Goal&action=AddView\', \'notfull\', \'yes\');return false;"><img src=\'/crm/themes/OA/images/sale_manage.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="18_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Goals&type=Goal&action=AddView\', \'notfull\', \'yes\');return false;">新建销售目标</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'19_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'19_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Announces&type=Sent&action=AddView\', \'shortcuts\', \'view_add_bbs\');return false;"><img src=\'/crm/images/notify_new.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="19_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Announces&type=Sent&action=AddView\', \'shortcuts\', \'view_add_bbs\');return false;">新建公告</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'20_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'20_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Buys&type=Import&action=AddView\', \'shortcuts\', \'view_add_import\');return false;"><img src=\'/crm/themes/OA/images/CreateProducts.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="20_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW_LOCAL2(\'/crm/index.php?module=Buys&type=Import&action=AddView\', \'shortcuts\', \'view_add_import\');return false;">新建入库申请</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'21_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'21_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Products&type=ListProducts&action=AddView\', \'notfull\', \'yes\');return false;"><img src=\'/crm/themes/OA/images/CreateProducts.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="21_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Products&type=ListProducts&action=AddView\', \'notfull\', \'yes\');return false;">新建产品</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'22_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'22_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Users&type=ListUsers&action=AddView\', \'notfull\', \'yes\');return false;"><img src=\'/crm/themes/OA/images/CreateUsers.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="22_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="OW(\'/crm/index.php?module=Users&type=ListUsers&action=AddView\', \'notfull\', \'yes\');return false;">新建员工帐号</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'8_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'8_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="location.href=\'/crm/index.php?module=SFAs&type=SFAInstance&action=ListView\';"><img src=\'/crm/themes/OA/images/calendar.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="8_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="location.href=\'/crm/index.php?module=SFAs&type=SFAInstance&action=ListView\';">SFA序列</A></td>\
			</tr>\
			<tr>\
			<td class="subMenuTDIcon" width="16" style="background-image: url(/crm/themes/OA/images/createBg.gif); background-repeat : repeat-y;"><a onMouseOver="document.getElementById(\'23_sh\').style.background=\'#eeeeee\';" onMouseOut="document.getElementById(\'23_sh\').style.background=\'#DFDFDF\';" class="subMenuLink" href="#" onclick="location.href=\'/crm/index.php?module=SFAs&type=SFATemplate&action=ListView\';"><img src=\'/crm/themes/OA/images/CreateWorkflowDefinition.gif\' alt=\'\'  border=\'0\' align=\'absmiddle\'></a></td>\
			<td nowrap id="23_sh" class="subMenuTD" onMouseOver="this.style.background=\'#eeeeee\';this.style.cursor=\'hand\';" onMouseOut="this.style.background=\'#DFDFDF\';this.style.cursor=\'auto\';">&nbsp;<a class="subMenuLink" href="#" onclick="location.href=\'/crm/index.php?module=SFAs&type=SFATemplate&action=ListView\';">SFA方案</A></td>\
			</tr>';

    this.document.getElementById("HideMenu").innerHTML =
	'<p>\
	<table cellpadding="0" cellspacing="0" border="0" width="180" class="leftColumnModuleHead" onMouseOver="hiliteItem(this,\'no\');">\
    	<tr>\
			<th style="background-image : url(/crm/themes/OA/images/moduleTab_middle.gif);" width="100%" height="21">快捷方式</th>\
		</tr>\
	</table>\
	<table cellpadding="0" cellspacing="0" border="0" class="subMenu" width="180" onMouseOver="hiliteItem(this,\'no\');">' +
	shortcuts_list +
	'</table>\
	</p>';

    this.document.getElementById("leftCol").innerHTML =
	'<table cellpadding="0" cellspacing="0" border="0" width="160">\
				<tr>\
					<td style="padding-right: 10px;">\
						<table cellpadding="0" cellspacing="0" border="0" width="100%" class="leftColumnModuleHead">\
	  						<tr>\
								<th style="background-image : url(/crm/themes/OA/images/moduleTab_middle.gif);" width="100%" height="21">快捷方式</th>\
							</tr>\
						</table>\
						<table cellpadding="0" cellspacing="0" border="0" class="subMenu" width="100%">' +
						shortcuts_list +
		    			'</table>\
						<img src="https://www.mooncrm.com/crm/themes/OA/images/blank.gif" alt="" width="160" height="1" border="0">\
					</td>\
				</tr>\
			</table>';
}

//for mooncrm v2.0 end

